Adding variable to GraphQL QUery

Hi all, I'm trying to create a paginated GraphQL query so I can step through each record set to help QA/Proof read some data we are storing in a GraphQL CMS (GraphCMS.com).

When I add the variable to the GraphQL query I am getting an error. I have tried several ways to do this.

{
  questions(first: 1, skip: $recordNumber) {
    questionId
    termAndTopic {
      term
    }
    answers {
      answerText
      correctAnswer
      rejoiner {
        markdown
      }
    }
    questionText {
      markdown
    }
    taskListItem {
      itemNumber
    }
    questionDifficulty
  }
}

How do you add a variable to a GraphQL query?

1 Like

Hey David!

These docs should help ya!

https://docs.retool.com/docs/shopify-integration#server-side-pagination-with-the-shopify-graphql-api
Basically, the variable can point to the dynamic value surrounding by double curly braces.

After you add in some $input variables to the query it will show the variables section in the UI (we're working on cleaning up that experience, it is a bit confusing at the moment). Here's an example of my GraphQL running with variables for pagination:



I'm not able to add a variable for some reason.

2 Likes

Would something like this screenshot work for you? The variable can point to the dynamic value surrounding by double curly braces.

After you add in some $input variables to the query it will show the variables section in the UI (we're working on cleaning up that experience, it is a bit confusing at the moment). That would look something like this:

These docs also walk through GraphQL variables a little as well! https://docs.retool.com/docs/shopify-integration#server-side-pagination-with-the-shopify-graphql-api

1 Like

I also encountered this problem. There were no errors in the query - the variables were declared correctly, but the UI was blocked. The code was copypasted.

And problem was solved when I manually rewrote the query. ¯_(ツ)_/¯

1 Like

@Egorrr just seeing this now—that sounds strange :eyes: Have you run into any similar problems recently?

@victoria The same thing happened to me as @Egorrr . Had to manually rewrite the whole query to get it to work!

1 Like

That's definitely not ideal. Filed a ticket to track this behavior and hopefully address it down the road!

1 Like

Any updates on this?

Hi @rschweter! No updates yet, unfortunately, but I bumped the ticket internally :slight_smile:

3 posts were split to a new topic: Need help declaring a GraphQL variable