Search code examples
graphqlgraphql-jsrelayreact-relay

GraphQL Relay introspection query fails: Unknown field '__type' on type 'Query'


I have a React application with a GraphQL client (Relay). I need to make an introspection query to get all the types of a certain enum. This is my query:

import { graphql } from 'react-relay'

export const corporationTypeEnumQuery = graphql`
  query corporationTypeEnumQuery {
    __type(name: "CorporationTypeEnum") {
      enumValues {
        name
      }
    }
  }
`

When I try to compile the app, Relay throws the following error:

Unknown field '__type' on type 'Query'

When I try the exact same query on GraphIQL (the playground that the server offers me), there is no error, and the query is successful.

Please tell me what could be wrong with my GraphQL query. Any suggestions are well received.


Solution

  • The __type must be part of your schema. Graphql spec by default said this should be hidden and not part of schema.. You need to extend your server to expose it or manually put them to schema..

    Server can handle that but compiler not since it require explicit definition in .graphql