ardatan / ardatan/graphql-tools
stitchSchemas with added fields inserting unneeded Fragment
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
**Describe the bug**
I am using `stitchSchemas` to proxy to a remote QGL API while at the same time adding a new field to one of the types. When my proxy server makes the request to the upstream API, it seems to be inserting an unneeded inline fragment into the query.
**To Reproduce**
Steps to reproduce the behavior:
Using this code to stitch:
```js
const ret = stitchSchemas({
inheritResolversFromInterfaces: true,
subschemas: [schema],
typeDefs: /* GraphQL */ `
extend interface Movie {
foo: String
}
extend type Movie_Type {
foo: String
}
`,
resolvers: {
Movie: {
foo: () => "foo",
},
},
});
```
and then I query with:
```gql
query{
Movie{
id
foo
}
}
```
the query sent to the upstream is:
```gql
{
Movie {
id
... on Movie_Type {
__typename
}
__typename
__typename
}
}
```
the schema (once merged) is:
```gql
interface Object {
id: ID!
}
interface BaseObject {
id: ID!
}
interface Movie {
id: ID!
foo: String
}
type Movie_Type implements Movie & Object & BaseObject {
id: ID!
foo: String
}
type Query {
Movie(filter: FilterMovie, order: OrderMovie, first: Int, last: Int, before: String, after: String): [Movie!]
}
```
**Expected behavior**
A query sent to upstream looking like:
```gql
{
Movie {
id
__typename
}
}
```
**Environment:**
- OS: MacOS
- "@graphql-tools/load": "^7.5.1",
- "@graphql-tools/schema": "^8.3.1",
- "@graphql-tools/stitch": "^8.4.3",
- "@graphql-tools/url-loader": "^7.7.1",
- NodeJS: v15.4.0
**Additional context**
Contributor guide
Research direction
Start by reproducing the issue with stitchSchemas, the supplied schema extensions, and the Movie query, then compare the upstream query with the expected output. The work is done when adding foo no longer causes the unnecessary inline fragment and duplicate __typename selections in the upstream request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100