graphql-query-to-json
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

graphql-query-to-json

Statement coverage Function coverage Line coverage Branches badge

This is a simple module that takes a graphQL query string and converts it into a JSON object. Think of it as the reverse of the excellent module json-to-graphql-query.

Installation

npm install graphql-query-to-json
# or
yarn add graphql-query-to-json

Usage

const {graphQlQueryToJson} = require("graphql-query-to-json")

const query = `
query GetThisStuff($name: String, $lastName: String) {
    viewer {
        personal(criteria: {
            name: $name,
            lastName: $lastName
        }) {
            name
            address
        }
    }
}
`
const result = graphQlQueryToJson(query, {
    variables: {
        name: "PETER",
        lastName: "SCHMIDT",
    },
})
expect(result).toEqual({
    query: {
        viewer: {
            personal: {
                __args: {
                    criteria: {
                        name: "PETER",
                        lastName: "SCHMIDT",
                    },
                },
                name: true,
                address: true,
            },
        },
    },
})

Debugging

Run the VSCode configuration "Jest" and set a breakpoint in the code wherever you feel the need to inspect.

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-query-to-json

Weekly Downloads

3,682

Version

2.0.1

License

MIT

Unpacked Size

141 kB

Total Files

27

Last publish

Collaborators

  • trayprod