Analyze your graphql schema using this package in order to understand relations between your types.
- install
gql-schema-relations-generator
:$ npm install --save gql-schema-relations-generator
Without taking care of fields descriptions
export default `
type Query {
posts: [Post]
}
type Author {
id: Int!
firstName: String
lastName: String
}
type Post {
id: Int!
title: String
author: Author
votes: Int
}
schema {
query: Query
}
`;
import Schema from './src/example/data/schema';
import { Resolvers } from './src/example/data/resolvers';
import { makeExecutableSchema } from "graphql-tools";
import { SchemaRelationsGenerator } from 'gql-schema-relations-generator';
const schema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers
});
let schemaRelations = new SchemaRelationsGenerator();
schemaRelations.generateRelationsMap(schema);
console.log(schemaRelations.getRelationsMap());
///The output will be: Map { 'Author' => Set { { rootName: 'Post' } } }
(Please note that this time we've added a description to author field under type Post
export default `
type Query {
posts: [Post]
}
type Author {
id: Int!
firstName: String
lastName: String
}
type Post {
id: Int!
title: String
#authorId
author: Author
votes: Int
}
schema {
query: Query
}
`;
import Schema from './src/example/data/schema';
import { Resolvers } from './src/example/data/resolvers';
import { makeExecutableSchema } from "graphql-tools";
import { SchemaRelationsGenerator } from 'gql-schema-relations-generator';
const schema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers
});
let schemaRelations = new SchemaRelationsGenerator();
schemaRelations.generateRelationsMap(schema, true);//In case the second parameter is true - descriptions are taken care of
console.log(schemaRelations.getRelationsMap());
///The output will be: Map {'Author' => Set { { rootName: 'Post', description: 'authorId' } } }