GraphQL Variable Merger
Merge a GraphQL query and variables JSON into an API request body.
Category: Dev Tools
When to use?
Use it to build a request body for GraphQL Playground, Postman, fetch, or axios by merging the query string and variables object into one JSON. Handy for consolidating scattered query and variable values into a request body.
How to use
- Enter the GraphQL query or mutation.
- Enter the variables JSON object.
- Check for JSON syntax errors.
- Generate and copy the request body JSON.
Input Explanation
Enter the query string and a valid variables JSON object. For requests without variables, use an empty object {}.
Calculation Basis
It validates variables with JSON.parse, wraps them as a { query, variables } object, and tidies with JSON.stringify. The query string keeps its line breaks in the request body.
Usage Examples
- Build a GraphQL request body - Make a GraphQL JSON body for Postman, fetch, or axios.
- Validate variables JSON - Catch variable syntax issues (missing commas, quote errors) that cause request failures first.
- Tidy API doc examples - Merge query and variables into one request example to paste into docs or reviews.
Examples
- query GetUser($id: ID!) + {"id":"1"} → {"query":"query GetUser...","variables":{"id":"1"}}
- A mutation plus variables JSON → a JSON object ready to use in a fetch body
Cautions
- Generated output is for reference; test carefully before production use.
- Set the Content-Type: application/json header too for actual requests.
Guides
GraphQL request body structure
A typical GraphQL HTTP request body holds the query string and a variables object. Even without variables, including an empty object keeps test tools and code examples consistent.
Validating variables
Variables must follow JSON syntax, so use double quotes for keys and strings. Missing commas or single quotes can cause real request failures.
Use with fetch/axios
The generated object moves easily into a fetch or axios request body. For real calls, set the Content-Type: application/json and auth headers separately.
Tidy doc examples
Writing query and variables separately in API docs or issues invites omissions. Merging them into one JSON body makes a reproducible request example.
FAQ
Can variables be empty?
Enter an empty object {}.
Does it handle query and variables together?
It merges the query string and variables JSON into an API request body object.
What if variables is invalid JSON?
Variables must be valid JSON; a malformed format is shown as an error.
Can I merge mutation requests too?
Yes. The query area accepts both query and mutation strings, with variables entered as a JSON object.
Related Tools
- GraphQL Formatter - Tidy GraphQL queries and mutations.
- JSON Formatter - Beautify or minify JSON strings instantly and check for validity errors.
- fetch → axios Converter - Convert fetch code into the axios request format.
- cURL → fetch Converter - Convert a cURL command into JavaScript fetch code.
- UUID Generator - Generate up to 20 cryptographically secure UUID v4 values at once.
- Password Generator - Generate secure random passwords in the browser by choosing length, character set, and count.