Skip to content

Bug in buildASTSchema when mutations are passed #100

@nemanja-stanarevic

Description

@nemanja-stanarevic

All, great work all around on graphql reference implementation, it's incredibly helpful.

I have been using the schema DSL parser and buildASTSchema to materialize the schema and noticed a small bug in utilities/buildASTSchema. Specifically, when both queryTypeName and mutationTypeName are passed to the buildASTSchema, the schema is not constructed correctly - query is missing.

I traced the bug down to the lines 150-157 of utilities/buildASTSchema, where if mutationTypeName is passed, schema object is constructed with the queryTypeName string instead of queryType object:

  if (isNullish(mutationTypeName)) {
    schema = new GraphQLSchema({query: queryType});
  } else {
    schema = new GraphQLSchema({
      query: queryTypeName,
      mutation: produceTypeDef(astMap[mutationTypeName]),
    });
  }

This should fix it -

  if (isNullish(mutationTypeName)) {
    schema = new GraphQLSchema({query: queryType});
  } else {
    schema = new GraphQLSchema({
      query: queryType,
      mutation: produceTypeDef(astMap[mutationTypeName]),
    });
  }

Note that this slipped since buildASTSchema tests don't include a case when both mutation and query are passed. I am happy to fix this, add a test and submit a PR, if welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions