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.
npm install graphql-query-to-jsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a GraphQL query with a variable into a JSON object. Requires the graphQlQueryToJson function and a variables object.
Access enum value via result.enumField.value, not result.enumField.
Ensure you provide a variables object matching the query variable definitions.
Pass variables as part of the options object: graphQlQueryToJson(query, { variables }).Add the missing variable: graphQlQueryToJson(query, { variables: { id: '123' } })Use import { graphQlQueryToJson } from 'graphql-query-to-json' (named import).