GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
526 stars 66 forks source link

Schema Introspection Failure #102

Closed ZirgVoice closed 1 year ago

ZirgVoice commented 1 year ago

When using federation, Apollo Sandbox throws an error:

Schema Introspection Failure

We couldn't parse your graphql schema, or building your schema failed. The expected format is either IntrospectionQuery or SDL string.

Error in GraphiQL:

Name \"__resolveReference\" must not begin with \"__\", which is reserved by GraphQL introspection.

Looking at the schema through PAW(RapidAPI), I noticed that the types to which I added key have __resolveReference. I'm not sure but maybe it shouldn't be there.

Maybe I'm doing something wrong, I'm trying to make a subgraph in a service that has a table with addresses and it should give addresses for the company through the gateway if the client requests a company with an address

In SDL I added:

extend type Company @key(fields: "addressID") {
  address: Address
  addressID: ID @external
}

In the scheme:

        Type(CompanyModel.self, as: "Company") {
            Field("addressID", at: \.addressID)
            Field("address", at: \.address)
        }.key(at: GraphQLResolver.addressToCompany) {
            Argument("addressID", at: \.addressID)
        }

I haven't used the gateway yet, just trying to open the schema via Apollo Sandbox

NeedleInAJayStack commented 1 year ago

Hey @ZirgVoice, thanks for reporting! You're probably the first one to be really using this feature so unfortunately you're hitting our rough edges.

I noticed that the types to which I added key have __resolveReference. I'm not sure but maybe it shouldn't be there.

I think I've fixed this issue - see this pull request: https://github.com/GraphQLSwift/Graphiti/pull/103

For background, these were an artifact of how we implemented federation (see here). We took inspiration from this portion of the Apollo Federation documentation. However, for some convenience reasons, we defined __resolveReference as a full-on field as opposed to just a resolver function, which made the introspection queries unhappy. I've reworked that in the pull request I linked above

Thanks again!

ZirgVoice commented 1 year ago

Now it works, thanks a lot!