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

extend does not work in minimal example #892

Closed
dyst5422 opened this issue May 31, 2017 · 1 comment
Closed

extend does not work in minimal example #892

dyst5422 opened this issue May 31, 2017 · 1 comment

Comments

@dyst5422
Copy link

dyst5422 commented May 31, 2017

I put this in the original issue regarding type extension (#483), but was unable to reopen it, so I put a new issue in as I believe this is really bad problem to have.

The problem is that the parser is fine with the extend keyword and properly builds an AST, but buildSchema does not properly insert the extend fields. If buildSchema does not handle it, I think having parse properly parse an AST might be a mistake, especially with so little documentation around the feature. Either buildSchema should compile the extend fields into the schema, or should error out on the extend syntax. Otherwise, it is very misleading and a less than obvious issue to hunt down.

The minimal example is below

import { buildSchema, graphql } from 'graphql';

const schema = buildSchema(`
type QuerySubset {
  hello: String
}

type Queries {
  querySubset: QuerySubset
}

extend type Queries {
  hello: String
}

type Query {
  Queries: Queries
}

schema {
  query: Query
}
`);

const rootResolver = {
  Queries: {
    querySubset: {
      hello: (): string => 'hello world',
    },
    hello: (): string => 'hello world',
  },
};

// Works fine
graphql(schema, `{ Queries { querySubset { hello } } }`, rootResolver).then(response => {
  console.log(response);
});

// Errors out with 'Cannot query field "hello" on type "Queries".'
graphql(schema, `{ Queries { hello } }`, rootResolver).then(response => {
  console.log(response);
});
@leebyron
Copy link
Contributor

Thanks for the report, @dyst5422. I just filed #922 which describes the fixing task for this issue.

As you describe above, buildASTSchema() is intended to build fully formed schema, while extendSchema() is intended to extend existing fully formed schema with new fields, typically for use in client-side or intermediate-only representations where the ultimate server only knows of a subset of the final definition.

I think your suggestion to throw an error is a great one, that would make debugging this far easier.

Closing so follow up can happen in #922.

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

No branches or pull requests

2 participants