This thread is a bit old but it was my first search result when I started trying to figure out why my environment variable would not work in a GraphQL call even when I tried to add it as a GraphQL variable, and I tried to use the examples above as a guide to no avail.
I have set up the tests themselves to run through the collection runner and compare data from a CSV to the result of a GraphQL call, which is working fine, but what I also need to do is be able to change what value I am sending in a test request depending on the environment. Eventually I’ll need to make this dynamic to have tests creating new users, but first, just sending a variable to retrieve data would be very valuable.
When I format it this way
{
"refID": {{recruitmentID}}
}
I get
{
"errors": [
{
"path": [
null
],
"locations": [],
"data": null,
"type": "ServiceError",
"message": "Must provide Source. Received: undefined"
}
]
}
but when I format it with double quotes around
{
"refID": "{{recruitmentID}}"
}
then I get
{
"errors": [
{
"path": [
null
],
"locations": [],
"data": null,
"type": "ServiceError",
"message": "Variable \"$refID\" is not defined."
}
]
}
At this point it feels like there is just something “stupid” I am missing.
In my environment variables, I have recruitmentID set to a string (that of the user’s recruitment record ID, a mix of letters and numbers) with no quotes around it.
In my request body, I’ve tried various permutations of
{
getRecord(ReferenceID: $refID,
) {
After looking at more examples, I tried
{
"ReferenceID": "{{recruitmentID}}"
}
and
{
getRecord($ReferenceID: String!
) {
and got no closer with
{
"errors": [
{
"path": [
null
],
"locations": [],
"data": null,
"type": "ServiceError",
"message": "Syntax Error: Expected Name, found $"
}
]
}
It seems like the examples I’m finding for how to use GraphQL variables with environment variables don’t contain the format I have to work with, so my question may boil down to syntax, as the above examples are sending a string, and I’m trying to send a key-value pair.
When I send the request as below, it does work:
getRecord((ReferenceID: "actual_string here"
) {
Does anyone have suggestions on what to try next?