1 {"slug":"/references/utils/utils.GraphQLUtils","title":"GraphQLUtils","frontmatter":{},"toc":[{"title":"Classes","id":"classes","level":2},{"title":"Functions","id":"functions","level":2},{"title":"Functions","id":"functions-1","level":2},{"title":"cleanGraphQLSchema","id":"cleangraphqlschema","level":3},{"title":"Parameters","id":"cleangraphqlschema-parameters","level":4},{"title":"Returns","id":"cleangraphqlschema-returns","level":4},{"title":"extractRelationsFromGQL","id":"extractrelationsfromgql","level":3},{"title":"Parameters","id":"extractrelationsfromgql-parameters","level":4},{"title":"Returns","id":"extractrelationsfromgql-returns","level":4},{"title":"gqlGetFieldsAndRelations","id":"gqlgetfieldsandrelations","level":3},{"title":"Parameters","id":"gqlgetfieldsandrelations-parameters","level":4},{"title":"Returns","id":"gqlgetfieldsandrelations-returns","level":4},{"title":"gqlSchemaToTypes","id":"gqlschematotypes","level":3},{"title":"Parameters","id":"gqlschematotypes-parameters","level":4},{"title":"Returns","id":"gqlschematotypes-returns","level":4},{"title":"graphqlSchemaToFields","id":"graphqlschematofields","level":3},{"title":"Example","id":"example","level":4},{"title":"Parameters","id":"graphqlschematofields-parameters","level":4},{"title":"Returns","id":"graphqlschematofields-returns","level":4}],"blocks":[{"kind":"heading","level":2,"text":"Classes","id":"classes"},{"kind":"linkList","items":[{"title":"GraphQLParser","href":"/references/utils/GraphQLUtils/classes/utils.GraphQLUtils.GraphQLParser"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions"},{"kind":"linkList","items":[{"title":"cleanGraphQLSchema","href":"/references/utils/utils.GraphQLUtils#cleangraphqlschema"},{"title":"extractRelationsFromGQL","href":"/references/utils/utils.GraphQLUtils#extractrelationsfromgql"},{"title":"gqlGetFieldsAndRelations","href":"/references/utils/utils.GraphQLUtils#gqlgetfieldsandrelations"},{"title":"gqlSchemaToTypes","href":"/references/utils/utils.GraphQLUtils#gqlschematotypes"},{"title":"graphqlSchemaToFields","href":"/references/utils/utils.GraphQLUtils#graphqlschematofields"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions-1"},{"kind":"heading","level":3,"text":"cleanGraphQLSchema","id":"cleangraphqlschema"},{"kind":"heading","level":4,"text":"Parameters","id":"cleangraphqlschema-parameters"},{"kind":"typeList","sectionTitle":"cleanGraphQLSchema","types":[{"name":"schema","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"cleangraphqlschema-returns"},{"kind":"typeList","sectionTitle":"cleanGraphQLSchema","types":[{"name":"schema","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notFound","type":"`Record<string, Record&#60;string, string&#62;>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"extractRelationsFromGQL","id":"extractrelationsfromgql"},{"kind":"markdown","html":"Extracts only the relation fields from the GraphQL type map."},{"kind":"heading","level":4,"text":"Parameters","id":"extractrelationsfromgql-parameters"},{"kind":"typeList","sectionTitle":"extractRelationsFromGQL","types":[{"name":"typeMap","type":"Map&#60;string, any&#62;","description":"The GraphQL schema TypeMap.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"extractrelationsfromgql-returns"},{"kind":"typeList","sectionTitle":"extractRelationsFromGQL","types":[{"name":"Map","type":"Map&#60;string, Map&#60;string, string&#62;&#62;","optional":false,"defaultValue":"","description":"A map where each key is an entity name, and the values are a map of relation fields and their corresponding entity type.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]},{"name":"Map","type":"Map&#60;string, string&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]},{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":3,"text":"gqlGetFieldsAndRelations","id":"gqlgetfieldsandrelations"},{"kind":"markdown","html":"Generate a list of fields and fields relations for a given type with the requested relations"},{"kind":"heading","level":4,"text":"Parameters","id":"gqlgetfieldsandrelations-parameters"},{"kind":"typeList","sectionTitle":"gqlGetFieldsAndRelations","types":[{"name":"schemaTypeMap","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"typeName","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relations","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"gqlgetfieldsandrelations-returns"},{"kind":"typeList","sectionTitle":"gqlGetFieldsAndRelations","types":[{"name":"string[]","type":"`string`[]","optional":false,"defaultValue":"","description":"Generate a list of fields and fields relations for a given type with the requested relations","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"gqlSchemaToTypes","id":"gqlschematotypes"},{"kind":"heading","level":4,"text":"Parameters","id":"gqlschematotypes-parameters"},{"kind":"typeList","sectionTitle":"gqlSchemaToTypes","types":[{"name":"__namedParameters","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"schema","type":"`GraphQLSchema`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"outputDir","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"filename","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"joinerConfigs","type":"[ModuleJoinerConfig](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.ModuleJoinerConfig)[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"schema","type":"`string`","description":"GraphQL schema for the all module's available entities and fields","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idPrefixToEntityName","type":"`Record<string, string>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"relationships","type":"[ModuleJoinerRelationship](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.ModuleJoinerRelationship)[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"extends","type":"`object`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"serviceName","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"primaryKeys","type":"`string`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isLink","type":"`boolean`","description":"If the module is a link module","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"linkableKeys","type":"`Record<string, string>`","description":"Keys that can be used to link to other modules. e.g &#123; product\\_id: \"Product\" &#125; \"Product\" being the entity it refers to","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isReadOnlyLink","type":"`boolean`","description":"If true it expands a RemoteQuery property but doesn't create a pivot table","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"extraDataFields","type":"`string`[]","description":"Fields that will be part of the link record aside from the primary keys that can be updated\nIf not explicitly defined, this array will be populated by databaseConfig.extraFields","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"databaseConfig","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"interfaceName","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"gqlschematotypes-returns"},{"kind":"typeList","sectionTitle":"gqlSchemaToTypes","types":[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"graphqlSchemaToFields","id":"graphqlschematofields"},{"kind":"markdown","html":"From graphql schema get all the fields for the requested type and relations"},{"kind":"heading","level":4,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nconst userModule = `\ntype User {\n id: ID!\n name: String!\n blabla: WHATEVER\n}\n\ntype Post {\n author: User!\n}\n`\n\nconst postModule = `\ntype Post {\n id: ID!\n title: String!\n date: String\n}\n\ntype User {\n posts: [Post!]!\n}\n\ntype WHATEVER {\n random_field: String\n post: Post\n}\n`\n\nconst mergedSchema = mergeTypeDefs([userModule, postModule])\nconst schema = makeExecutableSchema({\n typeDefs: mergedSchema,\n})\n\nconst fields = graphqlSchemaToFields(types, \"User\", [\"posts\"])\n\nconsole.log(fields)\n\n// [\n// \"id\",\n// \"name\",\n// \"posts.id\",\n// \"posts.title\",\n// \"posts.date\",\n// ]\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"graphqlschematofields-parameters"},{"kind":"typeList","sectionTitle":"graphqlSchemaToFields","types":[{"name":"schemaTypeMap","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"typeName","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relations","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"graphqlschematofields-returns"},{"kind":"typeList","sectionTitle":"graphqlSchemaToFields","types":[{"name":"string[]","type":"`string`[]","optional":false,"defaultValue":"","description":"From graphql schema get all the fields for the requested type and relations","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]}]}