www/apps/resources/references/utils/utils.GraphQLUtils/page.mdx
import { TypeList } from "docs-ui"
<TypeList types={[{"name":"schema","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="cleanGraphQLSchema"/>
<TypeList types={[{"name":"schema","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notFound","type":"Record<string, Record<string, string>>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="cleanGraphQLSchema"/>
<TypeList types={[{"name":"schema","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notFound","type":"Record<string, Record<string, string>>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="cleanGraphQLSchema"/>
Extracts only the relation fields from the GraphQL type map.
<TypeList types={[{"name":"typeMap","type":"Map<string, any>","description":"The GraphQL schema TypeMap.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="extractRelationsFromGQL"/>
<TypeList types={[{"name":"Map","type":"Map<string, Map<string, string>>","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<string, string>","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":[]}]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="extractRelationsFromGQL"/>
Generate a list of fields and fields relations for a given type with the requested relations
<TypeList 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":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="gqlGetFieldsAndRelations"/>
<TypeList 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":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="gqlGetFieldsAndRelations"/>
<TypeList 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[]","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[]","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 { product\_id: "Product" } "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":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="gqlSchemaToTypes"/>
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="gqlSchemaToTypes"/>
From graphql schema get all the fields for the requested type and relations
const userModule = `
type User {
id: ID!
name: String!
blabla: WHATEVER
}
type Post {
author: User!
}
`
const postModule = `
type Post {
id: ID!
title: String!
date: String
}
type User {
posts: [Post!]!
}
type WHATEVER {
random_field: String
post: Post
}
`
const mergedSchema = mergeTypeDefs([userModule, postModule])
const schema = makeExecutableSchema({
typeDefs: mergedSchema,
})
const fields = graphqlSchemaToFields(types, "User", ["posts"])
console.log(fields)
// [
// "id",
// "name",
// "posts.id",
// "posts.title",
// "posts.date",
// ]
<TypeList 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":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="graphqlSchemaToFields"/>
<TypeList 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":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="graphqlSchemaToFields"/>