Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid schmea with interface extension does not fail #2199

Closed
realdoug opened this issue Sep 25, 2019 · 1 comment
Closed

Invalid schmea with interface extension does not fail #2199

realdoug opened this issue Sep 25, 2019 · 1 comment
Labels

Comments

@realdoug
Copy link

Perhaps this is user error, but is the following schema valid? Based on my reading of the language spec, this program should fail with a validation exception:

var { graphql, buildSchema, printSchema } = require("graphql");

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: Person
  }

  interface NamedEntity {
    fullName: String
  }

  extend interface NamedEntity {
    nickname: String
  }

  type Person implements NamedEntity {
    isCool: Boolean
    fullName: String
  }
`);


var root = {
  hello: () => {
    return { isCool: true };
  }
};

graphql(schema, "{ hello { isCool } }", root).then(response => {
  console.log(response);
});

yet, it executes with no problems. Rolling the nickname field into the original NamedEntity portion, and removing the extension (see below) does result in a schema validation error.

  type Query {
    hello: Person
  }

  interface NamedEntity {
    fullName: String
    nickname: String
  }

  type Person implements NamedEntity {
    isCool: Boolean
    fullName: String
  }

So my question is, despite being a bit of a contrived example, is this a bug?

@IvanGoncharov
Copy link
Member

@realdoug Thanks for detailed report 👍

Perhaps this is user error, but is the following schema valid?

Yes, it's invalid. The problem here is that buildSchema silently ignores extensions so
nickname is never added. It's already reported in #922 and I finishing adding support for extensions and it will be included in upcoming 15.0.0-alpha.0 (ETA later this week).

Meanwhile you wan workaround using extendSchema:

var { graphql, buildSchema, extendSchema, parse, printSchema } = require("graphql");

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: Person
  }

  interface NamedEntity {
    fullName: String
  }

  type Person implements NamedEntity {
    isCool: Boolean
    fullName: String
  }
`);

schema = extendSchema(schema, parse(`
  extend interface NamedEntity {
    nickname: String
  }
`));

var root = {
  hello: () => {
    return { isCool: true };
  }
};

graphql(schema, "{ hello { isCool } }", root).then(response => {
  console.log(response);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants