apollographql / apollographql/federation

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

Open
#3,040 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
727
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

### 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!
}
```
4. 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."

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the listed steps with @apollo/subgraph's printSubgraphSchema() and the schema file option, then inspect where the generated schema is parsed during the subgraph schema check. Done means the generated schema no longer causes the DOES_NOT_PARSE linter violation when only extend type Query is defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.