graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

stitchSchemas with added fields inserting unneeded Fragment

Open cancan101 opened this issue 3 years ago • 0 comments

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:

  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:

query{
  Movie{
    id
    foo
  }
}

the query sent to the upstream is:

{
  Movie {
    id
    ... on Movie_Type {
      __typename
    }
    __typename
    __typename
  }
}

the schema (once merged) is:

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:

{
  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

cancan101 avatar Feb 21 '22 22:02 cancan101