GraphiQL API Documentation
    Preparing search index...

    Function getVariablesJSONSchema

    Utilities useful for language services across runtimes

    • Generates a JSONSchema6 valid document for operation(s) from a map of Map<string, GraphQLInputType>.

      It generates referenced Definitions for each type, so that no graphql types are repeated.

      Note: you must install @types/json-schema if you want a valid result type

      Parameters

      Returns JSONSchema6

      '

      simple usage:

      import { parse } from 'graphql'
      import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
      const variablesToType = collectVariables(parse(query), schema)
      const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema)

      advanced usage:


      import { parse } from 'graphql'
      import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
      const variablesToType = collectVariables(parse(query), schema)

      // you can append `markdownDescription` to JSON schema, which monaco-json uses.
      const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema, { useMarkdownDescription: true })

      // let's say we want to use it with an IDE extension that expects a JSON file
      // the resultant object literal can be written to string
      import fs from 'fs/promises'
      await fs.writeFile('operation-schema.json', JSON.stringify(JSONSchema6Result, null, 2))