1

I have a this graphql query:

import { graphql } from '../__generated__/gql';

// typeof IndexPageQuery is unknown
const IndexPageQuery = graphql(`
  query IndexPageQuery {
    user {
      ...UserInputFragment
    }
  }
  ${UserInputFragment}
`);

And when i run this code:

const { data } = await apolloClient.query(IndexPageQuery);

TS throw error:

Argument of type 'unknown' is not assignable to parameter of type 'QueryOptions<OperationVariables, any>'.ts(2345)

Why IndexPageQuery always has type unknown? Does anyone know what I'm doing wrong? Thanks

1 Answer 1

3

I'm Charly, from The Guild, working on GraphQL Code Generator.

The preset: 'client' does not require to include fragments documents in the GraphQL operation definition (it does it for you automatically).

To fix your issue, please replace your IndexPageQuery with the following:

const IndexPageQuery = graphql(`
  query IndexPageQuery {
    user {
      ...UserInputFragment
    }
  }
`);
2
  • I have the exact same problem, but leaving out the inclusion does not fully solve it for me. I then get the error UnknownFragment: "UserInputFragment" from useQuery(). If I do not refer to the fragment by including the variable anymore, where/how do I properly define the fragment so that it is definitely considered and auto-included by the GraphQL Code Generator?
    – PhilJay
    Aug 4 at 8:26
  • Ok I could solve it now by also including *.graphql files in the documents: [] filter in my CodegenConfig and then just created a .graphql file where I define my fragments. (The rest of my schema I fetch from an GQL Endpoint where I do not want the fragments to be included)
    – PhilJay
    Aug 18 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.