{"id":47929,"library":"graphql-query-to-json","title":"graphql-query-to-json","description":"Converts GraphQL query, mutation, and subscription strings into structured JSON objects, enabling programmatic manipulation and analysis of GraphQL queries. This TypeScript library (v2.0.6, actively maintained on GitHub) is the reverse of json-to-graphql-query. Key differentiators: full GraphQL support including variables, arguments, aliases, inline fragments, enums, and type safety with comprehensive TypeScript definitions. It provides predictable transformation rules and descriptive error handling. Active development, regular releases on npm.","status":"active","version":"2.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/trayio/graphql-query-to-json","tags":["javascript","typescript"],"install":[{"cmd":"npm install graphql-query-to-json","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-query-to-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-query-to-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"TypeScript type definitions shipped with the package","package":"typescript","optional":true}],"imports":[{"note":"Named export; default import does not exist.","wrong":"import graphQlQueryToJson from 'graphql-query-to-json'","symbol":"graphQlQueryToJson","correct":"import { graphQlQueryToJson } from 'graphql-query-to-json'"},{"note":"Use type import for TypeScript to avoid runtime import.","wrong":"import { QueryObject } from 'graphql-query-to-json'","symbol":"QueryObject","correct":"import type { QueryObject } from 'graphql-query-to-json'"},{"note":"Options is a type, not a value; use type import.","wrong":"import { Options } from 'graphql-query-to-json'","symbol":"Options","correct":"import type { Options } from 'graphql-query-to-json'"}],"quickstart":{"code":"import { graphQlQueryToJson } from 'graphql-query-to-json';\n\nconst query = `\n  query GetUser($id: ID!) {\n    user(id: $id) {\n      name\n      email\n      profile {\n        bio\n      }\n    }\n  }\n`;\n\nconst variables = { id: '123' };\n\nconst result = graphQlQueryToJson(query, { variables });\n\nconsole.log(JSON.stringify(result, null, 2));","lang":"typescript","description":"Converts a GraphQL query with a variable into a JSON object. Requires the graphQlQueryToJson function and a variables object."},"warnings":[{"fix":"Access enum value via result.enumField.value, not result.enumField.","message":"Enums are wrapped in an object with a 'value' property (e.g., { value: 'ACTIVE' }), not represented as strings or enum values directly.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Ensure you provide a variables object matching the query variable definitions.","message":"Variables must be passed in the options object; omitting variables when the query uses them throws an error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass variables as part of the options object: graphQlQueryToJson(query, { variables }).","message":"The function signature previously accepted (query, variables, options) but now accepts (query, options) where options includes variables.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"search_vec":"'activ':29,70 'alias':50 'analysi':21 'argument':49 'comprehens':58 'convert':6 'definit':60 'descript':67 'develop':71 'differenti':43 'enabl':17 'enum':53 'error':68 'fragment':52 'full':44 'github':32 'graphql':2,7,23,40,45 'graphql-query-to-json':1 'handl':69 'includ':47 'inlin':51 'javascript':76 'json':5,15,38 'json-to-graphql-queri':37 'key':42 'librari':27 'maintain':30 'manipul':19 'mutat':9 'npm':75 'object':16 'predict':63 'programmat':18 'provid':62 'queri':3,8,24,41 'regular':72 'releas':73 'revers':35 'rule':65 'safeti':56 'string':12 'structur':14 'subscript':11 'support':46 'transform':64 'type':55 'typescript':26,59,77 'v2.0.6':28 'variabl':48","created_at":"2026-06-07T16:54:03.223586+00:00","updated_at":"2026-06-07T16:54:03.223586+00:00","problems":[{"fix":"Add the missing variable: graphQlQueryToJson(query, { variables: { id: '123' } })","cause":"Missing required variable in the options.variables object.","error":"Error: Variable \"$id\" of type \"ID!\" is required but not provided."},{"fix":"Use import { graphQlQueryToJson } from 'graphql-query-to-json' (named import).","cause":"Using default import instead of named import.","error":"TypeError: graphQlQueryToJson is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/trayio/graphql-query-to-json","github":"https://github.com/trayio/graphql-query-to-json","docs":null,"changelog":null,"pypi":null,"npm":"graphql-query-to-json","openapi_spec":null,"status_page":null,"smithery":null,"categories":["developer-tools","databases"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}