0

I'm currently writing a next.js app. I have got a query in apollo graphql, that I want to attach a variable to, in the header of the request. The variable is called x-hasura-a .

Trying to use it like:

const variable ='Test'

  const get_query = gql'...'

  const {
    loading,
    error,
    data,
  } = useQuery(
    get_query,
    {
      variables: { asdf: 'asdf' },
    },
    {
      options: {
        context: {
          headers: {
            'x-hasura-a': variable,
          },
        },
      },
    },
  )

Does not work. Any suggestions?

John Mayer
  • 1,039
  • 1
  • 11
  • 17

1 Answers1

0

According to the docs, context is a property of the options config object.

You already have variables defined in there. Just add context.

Like so:

const variable ='Test'

  const get_query = gql'...'

  const {
    loading,
    error,
    data,
  } = useQuery(
    get_query,
    {
      variables: { asdf: 'asdf' },
      context: {
        headers: {
          'x-hasura-a': variable,
        },
      },
    }
  )
Abraham Labkovsky
  • 1,771
  • 6
  • 12