
Kombai AI converts Figma designs into clean, responsive frontend code. It helps developers build production-ready UIs faster while keeping design accuracy and code quality intact.

Discover what’s new in The Replay, LogRocket’s newsletter for dev and engineering leaders, in the October 22nd issue.

John Reilly discusses how software development has been changed by the innovations of AI: both the positives and the negatives.

Learn how to effectively debug with Chrome DevTools MCP server, which provides AI agents access to Chrome DevTools directly inside your favorite code editor.
Would you be interested in joining LogRocket's developer community?
Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
Sign up now
3 Replies to "GraphQL variables in simple terms"
Testing variables in some application is pretty straightforward. However, how do you use variables in a standard fetch call using code?
In the body of the request stringify your graphql query like this:- hope it helps
fetch(‘https://api.hashnode.com’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
Authorization: ”,
},
body: JSON.stringify({
query:
‘mutation createStory($input: CreateStoryInput!){ createStory(input: $input){ code success message } }’,
variables: {
input: {
title: ‘What are the e2e testing libraries you use ?’,
contentMarkdown: ‘# You can put Markdown here.\n***\n’,
tags: [
{
_id: ‘56744723958ef13879b9549b’,
slug: ‘testing’,
name: ‘Testing’,
},
],
coverImageURL:
‘https://codybontecou.com/images/header-meta-component.png’,
},
},
}),
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res)))
Thank you! After endless hours trying to use string interpolation to inject my $token into the GraphQL request and having to deal with needing to escape quotation mark characters, this helped me correctly use variables for my request.