mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 09:56:44 +00:00 
			
		
		
		
	 81a9a63cad
			
		
	
	
		81a9a63cad
		
			
		
	
	
	
	
		
			
			* Fixes #9804 * Fixes isPrivateAttribute function in strapi utils to take into account the private property within an attribute * removing comment * removing isNotPrivate function + adding call to already existing isPrivateAttribute function instead of isNotPrivate * isPrivateAttribute fixed based on coments from Alexandre and confirmed that the model does indeed contain all private fields in an array at startup time * removing isNotPrivate function and fixing generateEnumDefinitions to use the already available isPrivateAttribute function * checking if created_at and update_at are also marked as private and if this is the case then hiding them * allowIds by default when generating the input model to see if the tests will pass * moving allowIds back to false by default * adding isTypeAttributeEnabled function to check if a type attribute has been disabled and remove it from the exported graphql schema * removing unused var * only using isTypeAttributeEnabled instead of isPrivateAttribute. * adding isPrivateAttribute at association level * Adding isNotPrivate back together with isTypeAttributeEnabled * adding unit test for removing a disabled attribute from a graphql schema * renaming person to player in the test model * Deleting the file as it has been renamed in the strapi master branch * fixing lint issues * fixing some lint issues * adding isTypeAttributeEnabled support * adding enumeration field in graphql * adding use strict; to test file * fixing test checking that disabled attributes in graphql are removed from the graphql schema * adding test for buidShadowCrud * Update packages/strapi-plugin-graphql/services/type-builder.js Co-authored-by: Jean-Sébastien Herbaux <jean-sebastien.herbaux@epitech.eu> Co-authored-by: Rmaroun <rmaroun@outlook.com> Co-authored-by: Jean-Sébastien Herbaux <jean-sebastien.herbaux@epitech.eu>
		
			
				
	
	
		
			100 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| const types = require('../services/type-builder');
 | |
| const buildShadowCrud = require('../services/shadow-crud');
 | |
| 
 | |
| const playerModel = {
 | |
|   attributes: {
 | |
|     lastname: {
 | |
|       type: 'text',
 | |
|     },
 | |
|     firstname: {
 | |
|       type: 'text',
 | |
|     },
 | |
|     age: {
 | |
|       type: 'integer',
 | |
|     },
 | |
|     level: {
 | |
|       type: 'enumeration',
 | |
|       enum: [
 | |
|         'amateur',
 | |
|         'intermediary',
 | |
|         'pro'
 | |
|       ],
 | |
|       default: 'amateur',
 | |
|     },
 | |
|   },
 | |
|   connection: 'default',
 | |
|   name: 'player',
 | |
|   description: '',
 | |
|   collectionName: '',
 | |
|   globalId: 'Player',
 | |
|   kind: 'collectionType',
 | |
|   modelName: 'player'
 | |
| };
 | |
| 
 | |
| describe('generateInputModel', () => {
 | |
|   test('removes disabled attributes', () => {
 | |
|     global.strapi = {
 | |
|       plugins: {
 | |
|         graphql: {
 | |
|           config: {
 | |
|             _schema: {
 | |
|               graphql: {
 | |
|                 type: {
 | |
|                   Player: {
 | |
|                     age: false,
 | |
|                     level: false,
 | |
|                   },
 | |
|                 },
 | |
|               },
 | |
|             },
 | |
|           },
 | |
|         },
 | |
|       },
 | |
|     };
 | |
|     expect(types.generateInputModel(playerModel, 'player')).toEqual(
 | |
|       `
 | |
|       input PlayerInput {
 | |
| 
 | |
|         lastname: String
 | |
| firstname: String
 | |
|       }
 | |
| 
 | |
|       input editPlayerInput {
 | |
|         
 | |
|         lastname: String
 | |
| firstname: String
 | |
|       }
 | |
|     `
 | |
|     );
 | |
|   });
 | |
| });
 | |
| 
 | |
| describe('buildShadowCrud', () => {
 | |
|   test('removes disabled attributes', () => {
 | |
|     global.strapi = {
 | |
|       plugins: {
 | |
|         graphql: {
 | |
|           config: {
 | |
|             _schema: {
 | |
|               graphql: {
 | |
|                 type: {
 | |
|                   Player: {
 | |
|                     age: false,
 | |
|                     level: false,
 | |
|                   },
 | |
|                 },
 | |
|               },
 | |
|             },
 | |
|           },
 | |
|         },
 | |
|       },
 | |
|     };
 | |
|     global.strapi.contentTypes = [playerModel]
 | |
|     global.strapi.components = {}
 | |
|     expect(JSON.stringify(buildShadowCrud({}))).toEqual(
 | |
|       '{"definition":"\\ntype Player {id: ID!\\nundefined: ID!\\nlastname: String\\nfirstname: String}\\n\\n      input PlayerInput {\\n\\n        lastname: String\\nfirstname: String\\n      }\\n\\n      input editPlayerInput {\\n        \\n        lastname: String\\nfirstname: String\\n      }\\n    ","query":{},"mutation":{},"resolvers":{"Query":{},"Mutation":{},"Player":{}}}'
 | |
|     );
 | |
|   });
 | |
| }); |