I've spent significant time confirming this is an issue before posting, including reviewing all relevant issues (open and closed). When sending variables, whether using GraphiQL, Postman, or a Go GraphQL client, they will not be picked up in the resolver. However, when inlining instead, it will work:
mutation {
create(myvar: "value") {
id
}
}
Variable myvar is set in GraphiQL, in POST Request body JSON, and in Go GraphQL client appropriately.
mutation($myvar: String) {
create(myvar: $myvar) {
id
}
}
input, ok := params.Args["myvar"]
log.Print(input, ok) // prints `<nil> false` when using variables, prints `value true` when inlined
I am using proper NewInputObject, InputObjectConfigFieldMap and InputObjectFieldConfig structs, which I can confirm because it does work when inlining. Can anyone confirm variables indeed do not work, or has anyone been able to get them to work?
Upon further investigation, the issue seemed to be not setting VariableValues on the graphql.Params type passed to graphql.Do(). Some extra work needs to be done to pull variables off of the request body and decode, but once this is done and added Resolvers will have access to params passed via variables and not just inlined.
res := graphql.Do(graphql.Params{
Schema: s,
RequestString: req.Query,
Context: ctx,
VariableValues: vars, // Variables from request body need to be passed manually here
})
Most helpful comment
Upon further investigation, the issue seemed to be not setting
VariableValueson thegraphql.Paramstype passed tographql.Do(). Some extra work needs to be done to pullvariablesoff of the request body and decode, but once this is done and added Resolvers will have access to params passed via variables and not just inlined.