'Variable $varname does not appear in any graphQL query

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



Solution 1:[1]

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
        }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manu Jo Varghese