cjoudrey / graphql-schema-linter

Validate GraphQL schema definitions against a set of rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unclear eslint errors

RoyLeibo opened this issue · comments

We are developing micro-services in NestJS-typescript, Each of them exposes a GraphQL schema. In order to expose a single graph, we are using a federation service, also in NestJS.

I was trying to integrate with '@graphql-eslint/eslint-plugin' and some strange exceptions were thrown:

Unknown directive "@key"

Those errors were solved following a GitHub issue: #210

I have created a new file with the type specifications according to the Apollo documentation: https://www.apollographql.com/docs/federation/federation-spec/#federation-schema-specification

After solving this issue, I am getting few more errors that I have no idea what they mean and how to solve them:

Parsing error: Cannot extend type "Query" because it is not defined. Did you mean "User"?

Cannot extend type "Mutation" because it is not defined.

Unknown type "Query". Did you mean "User"?

Unknown type "Mutation".eslint

This is my schema:

extend type Query {
  users: [User]
  user(email: EmailAddress!): User
}

extend type Mutation {
  createUser(userData: UserData!): User
}

type User @key(fields: "email") {
  email: String!
  name: String
}

input UserData {
  email: String!
  name: String
}

Does anyone have an idea why I am getting those errors?

Sorry for the late reply.

If I were to guess, I think it's because the schema you pasted doesn't define Mutation or Query, but rather only extends them.

I was going to suggest defining empty types in the same file you define @key, but unfortunately that wouldn't be valid either. 🤔

I'll have to think about this a bit, but unfortunately, this validation error comes from GraphQL.js which graphql-schema-linter uses to parse schemas.