Skip to content

Issue parsing printed GraphQL schema (documentation that ends in ") #1337

@benjie

Description

@benjie

If a description in a GraphQL schema ends with a quotation mark " then you can no longer parse(printSchema(schema)) - i.e. the printed schema cannot be parsed.

Here's a small script that reproduces the issue:

const {
  GraphQLObjectType,
  GraphQLSchema,
  GraphQLInt,
  printSchema,
  parse,
} = require("graphql");

const makeSchema = withBadComment =>
  new GraphQLSchema({
    query: new GraphQLObjectType({
      name: "Query",
      fields: {
        hello: {
          type: GraphQLInt,
        },
      },
      description: withBadComment
        ? `Something ending with a "quote"`
        : `Something with "quote" inside.`,
    }),
  });

function test(schema) {
  const schemaString = printSchema(schema);
  console.log(schemaString);

  const parsed = parse(schemaString);
  console.dir(parsed);
}

console.log("Testing good schema");
test(makeSchema(false));

console.log();
console.log();
console.log(
  "********************************************************************************"
);
console.log();
console.log();
console.log("Testing bad schema");
test(makeSchema(true));

GraphQL version: 0.12.3

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