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

Using extend type Query without type Query leads to Linter violation error being reported via Apollo Service Check when using schema file option. #3040

Open
ngupta53 opened this issue Jun 18, 2024 · 3 comments

Comments

@ngupta53
Copy link

Issue Description

I have a type definition defined using extend query in our schema like below -

extend type Query {
  testGraphQl(id: Int!): TestGraphQl!
}

I do not have type Query defined anywhere in the schema.
I want to use schema file option to run the schema checks and pass the generated schema to it. To generate the schema graphql file, I am using @apollo/subgraph printSubgraphSchema() method to get the schema output and then write to a file.
The schema file that gets generated has a type Query string appearing on top of extend type Query, something like this -

type Query

extend type Query {
  testGraphQl(id: Int!): TestGraphQl!
}

When I run the schema check, it complains about the Linter violation error 'DOES_NOT_PARSE' due to "The schema linter raises this violation if it attempts to read a malformed GraphQL schema."

The printSubgraphSchema() method itself outputs that type Query string and then the Linter reports it. This should not be happening. Raising this issue to look into this and fix this issue.

Link to Reproduction

n/a

Reproduction Steps

  1. Define a type extending type Query without having type Query specified anywhere in the schema.
  2. Generate a schema file using printSubgraphSchema() method of @apollo/subgraph to print the schema output and write it to a file.
  3. Note that generated schema graphql file has additional type Query present.
type Query

extend type Query {
  testGraphQl(id: Int!): TestGraphQl!
}
  1. Run subgraph schema check using the generate schema file passing the schema file option. Note that the schema check fails with Linter violation error 'DOES_NOT_PARSE' due to "The schema linter raises this violation if it attempts to read a malformed GraphQL schema."
@ngupta53
Copy link
Author

Could someone take a look at this and suggest?

1 similar comment
@ngupta53
Copy link
Author

ngupta53 commented Jul 8, 2024

Could someone take a look at this and suggest?

@duckki
Copy link
Contributor

duckki commented Jul 12, 2024

Suppose a subgraph schema like this:

      type TestGraphQl {
        id: Int!
      }

      extend type Query {
         testGraphQl(id: Int!): TestGraphQl!
      }

It's a valid subgraph schema, but it is not a valid GraphQL schema by itself (since type Query is not defined before extending it). It's unclear to me how you went from step (1) to step (2). How did you construct a GraphQLSchema object when the input schema is not a valid GraphQL schema?

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