2

I'm trying to reference a variable in my graphql query. I thought this was going to be straightforward but I'm obviously missing something. Can someone educate me on this?

mutation {
    requestAccessToken(
        input: {
            grant_type: CLIENT_CREDENTIALS
            client_id: $clientId
            client_secret: $clientSecret
        }
    ) {
        access_token
    }
}

Variables

{
    "clientId": "1234",
    "clientSecret": "sekeret"
}

I tried through insomnia and GraphQL playground and the results are the same. The program tells me there's no variables defined, and where I defined them it tells me they're not being used.

I made the variables basic strings to rule out any formatting weirdness with getting them out of my environment and I get the same issue.

Example

Tulio Elputo
  • 35
  • 1
  • 4

1 Answers1

4

You should accept the variable in mutation header just like this,

    mutation($clientId: Int!,$clientSecret: String!) {
        requestAccessToken(
            input: {
                grant_type: CLIENT_CREDENTIALS
                client_id: $clientId
                client_secret: $clientSecret
            }
        ) {
            access_token
        }
}
Manu Jo Varghese
  • 360
  • 1
  • 14