Closed
Description
I noticed an issue with loading a GraphQLSchema
using introspection JSON.
Given the following introspection JSON:
https://gist.github.com/dotansimha/c25f0ce38382086f55f5382da7dcbcb8
If I'm running the following code:
const introspection = require('./schema.json');
const { buildClientSchema } = require('graphql');
const schema = buildClientSchema(introspection);
const allTypes = schema.getTypeMap(); // Valid, all types are there
const rootNode = schema.astNode; // undefined
const allTypesAst = Object.keys(allTypes).map(key => allTypes[key].astNode); // Array of `undefined`
I know buildClientSchema
should return a GraphQLSchema
without resolvers and anything else, but is there a reason for removing the astNode
fields?
My current workaround is to print the schema into a string
, parse to into a Document
using parse
and then build the schema again using buildASTSchema
:
const introspection = require('./schema.json');
const { buildClientSchema, buildASTSchema, parse, printSchema } = require('graphql');
const schema = buildClientSchema(introspection);
const validSchema = buildASTSchema(parse(printSchema(schema)));
const allTypesAst = Object.keys(allTypes).map(key => allTypes[key].astNode); // Valid ASTs