Skip to content

Extended types are ignored #227

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

Closed
Baloche opened this issue May 15, 2019 · 5 comments
Closed

Extended types are ignored #227

Baloche opened this issue May 15, 2019 · 5 comments
Labels

Comments

@Baloche
Copy link

Baloche commented May 15, 2019

Hello 👋

My schema :

type Query {
  games: [Game]!
}

type Game {
  id: ID!
  name: String!
}

extend type Game {
  playersCount: Int!
}

My query :

const query = gql`
  query games {
    games {
      id
      name
      playersCount
  }
`

The warning I get :

Cannot query field "playersCount" on type "Game". eslint(graphql/template-strings)

Extended types are not supported by the plugin or am I doing something wrong ?

@jnwng
Copy link
Contributor

jnwng commented May 15, 2019

it'd be useful to get more information about the schema you're using — if you wouldn't mind, can you share the actual JSON representation of the schema that you started with?

it'd also be useful to see how you're configuring this plugin in your .eslintrc to figure out whether the extend type is showing up in the schema to begin with.

@jnwng jnwng added the question label May 15, 2019
@Baloche
Copy link
Author

Baloche commented May 16, 2019

I'm sorry, I don't get which informations you need. This is my entire schema defined in a schema.graphql file.

Here is my .eslintrc.js where schemaString is my entire schema as a string :

module.exports = {
  extends: ['plugin:react/recommended'],
  plugins: ['graphql'],
  rules: {
    'graphql/template-strings': ['error', { env: 'apollo', schemaString }],
    'graphql/required-fields': ['error', { env: 'apollo', schemaString, requiredFields: ['id'] }],
  },
}

I don't have myself a JSON representation of the schema.

@jnwng
Copy link
Contributor

jnwng commented May 16, 2019 via email

@Baloche
Copy link
Author

Baloche commented May 16, 2019

Yes, schemaString is the schema I already shared, in SDL, as a string.

@jnwng
Copy link
Contributor

jnwng commented May 18, 2019

this took me down a huge rabbit hole and i found an answer.

under the hood, eslint-plugin-graphql is just delegating to graphql-js to handle schema parsing, we just provide a few options of how you pass that schema to validated your graphql documents. in this case, with the schemaString option, we call buildSchema from the graphql package, which in turn calls buildASTSchema internally, which led me to this open issue on supporting extend within the buildASTSchema, which looks like it's slated for release in [email protected] (we dont have support for that version just yet)

however, afaik, graphql-tools already supports creating schemas with the extend keyword, so if you create the schema using graphql-tools, you can send it via the schemaJson option and this should all lint properly.

i hope this helps!

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