Skip to content

All astNode fields are undefined when schema is loaded using buildClientSchema #1575

Closed
@dotansimha

Description

@dotansimha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions