graphql-document-tools

0.0.6 • Public • Published

graphql-document-tools

Tools to perform analysis on GraphQL documents.

Install

$ yarn add --dev graphql-document-tools

Usage

graphql-document-tools exports the following functions:

extractFieldPaths

Extracts a list of field "paths" contained in a GraphQL document.

e.g. for the following query:

query GET_BUSINESS($BizId: String) {
    business(id: $BizId) {
        name
        location {
            city
        }
    }
}

We would return the following set of field paths:

["Query.business", "Business.name", "Business.location", "Location.city"]

API

extractFieldPaths(
    /**
     * The text of the document to analyse, in raw string format
     */
    documentText: string,
    /**
     * The text of your schema, in string SDL format (e.g. as created by printSchema)
     * @see https://graphql.org/graphql-js/utilities/#printschema
     */
    schemaText: string,
): Set<string>

Sample Usage:

import { extractFieldPaths } from 'graphql-document-tools';
const fieldPaths = extractFieldPaths(schemaText, documentString);

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-document-tools

Weekly Downloads

7

Version

0.0.6

License

MIT

Unpacked Size

34.4 kB

Total Files

8

Last publish

Collaborators

  • magicmark