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

The type __Schema is not an object in the defined schema, but the GraphQL document is traversing it. #345

Open
yayvery opened this issue Apr 3, 2021 · 5 comments
Labels
Bug Something isn't working Needs more info Requires more information from reporter(s)

Comments

@yayvery
Copy link

yayvery commented Apr 3, 2021

Uncaught (in promise) Graphcache Error: Invalid Object type: The type `__Schema` is not an object in the defined schema, but the GraphQL document is traversing it.
(Caused At: "IntrospectionQuery" query)

Started getting this error when I passed my schema.json to cacheExchange. Seems to be because __Schema is not defined in my schema.json. Does not seem to have any actual effects and can safely be ignored, but the error should still be fixed.

Possibly related to #269, urql-graphql/urql#889

@yayvery yayvery added the Bug Something isn't working label Apr 3, 2021
@andyrichardson
Copy link
Collaborator

Hey @danbeneventano thanks for the report!

We added a fix for #269 here - urql-graphql/urql#893

As for why you're seeing a similar issue, I suspect it's related to your schema using the __Schema type outside of the __schema property - any chance you could share your schema?

@andyrichardson andyrichardson added the Needs more info Requires more information from reporter(s) label Apr 21, 2021
@disbelief
Copy link

disbelief commented May 10, 2021

I'm having the same issue. Definitely seems to be due to the introspection query that devtoolsExchange runs because when I disable that exchange the error disappears.

Had a look at the fix in urql-graphql/urql#893 but I don't see this logic in the latest version of the schemaPredicates.ts.

Perhaps this is a regression?

@disbelief
Copy link

Ah I see the logic changed to use a regex that should match any fieldName beginning with __

For reference, here's the complete error I'm seeing:

Unhandled Rejection (Graphcache Error): Invalid Object type: The type `__Schema` is not an object in the defined schema, but the GraphQL document is traversing it.
(Caused At: "IntrospectionQuery" query)
https://bit.ly/2XbVrpR#3

@disbelief
Copy link

Perhaps the problem isn't with the __schema field, but rather with the __typename: "__Schema" in the introspection query response?

Screen Shot 2021-05-11 at 09 45 46

@disbelief
Copy link

After some more digging I am fairly confident the error is happening because the query used to generate the schema that cacheExchange uses is different from the query devtoolsExchange uses.

Specifically, the cacheExchange query is missing all of the __typename fields that the devtoolsExchange introspection query includes.

I'm generating the schema for cacheExchange using the @graphql-codegen/urql-introspection plugin.

I've opened a ticket for graphql-codegen with full details here: dotansimha/graphql-code-generator#5981

However maybe it's possible for the GraphCache exchange to handle this specific situation better? Here's where the error is coming from: https://github.com/FormidableLabs/urql/blob/4c1a9d9bd3df55207aeff1ffc3e2b3262f27cbc9/exchanges/graphcache/src/ast/schemaPredicates.ts#L70

Here are the two introspection queries and their diff:

########################################
# graphql-codegen introspection query:
########################################
query IntrospectionQuery {
  __schema {
    queryType {
      name
    }
    mutationType {
      name
    }
    subscriptionType {
      name
    }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
      }
    }
  }
}

fragment FullType on __Type {
  kind
  name
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}

fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}

########################################
# urql-devtools introspection query:
########################################
query IntrospectionQuery {
  __schema {
    queryType {
      name
      __typename
    }
    mutationType {
      name
      __typename
    }
    subscriptionType {
      name
      __typename
    }
    types {
      ...FullType
      __typename
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
        __typename
      }
      __typename
    }
    __typename
  }
}

fragment FullType on __Type {
  kind
  name
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
      __typename
    }
    type {
      ...TypeRef
      __typename
    }
    isDeprecated
    deprecationReason
    __typename
  }
  inputFields {
    ...InputValue
    __typename
  }
  interfaces {
    ...TypeRef
    __typename
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
    __typename
  }
  possibleTypes {
    ...TypeRef
    __typename
  }
}

fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
    __typename
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
                __typename
              }
              __typename
            }
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

Here is the diff between the two queries:

5d4
<       __typename
9d7
<       __typename
13d10
<       __typename
17d13
<       __typename
25d20
<         __typename
27d21
<       __typename
29d22
<     __typename
42d34
<       __typename
46d37
<       __typename
50d40
<     __typename
54d43
<     __typename
58d46
<     __typename
65d52
<     __typename
69d55
<     __typename
78d63
<     __typename
107d91
<                 __typename
109d92
<               __typename
111d93
<             __typename
113d94
<           __typename
115d95
<         __typename
117d96
<       __typename
119d97
<     __typename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Needs more info Requires more information from reporter(s)
Projects
None yet
Development

No branches or pull requests

3 participants