@graphql-tools/documents
Utilities for GraphQL documents.
Last updated 3 years ago by ardatan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @graphql-tools/documents 
SYNC missed versions from official npm registry.

@graphql-tools/documents

Utilities for GraphQL documents.

Install

yarn install @graphql-tools/documents

Contents

Print GraphQL Documents

A stable way to print a GraphQL document. All executable/fragment variable definitions, fields are printed in a stable way. Useful for stuff like persisted GraphQL operations.

Usage

import { parse } from 'graphql'
import { printExecutableGraphQLDocument } from '@graphql-tools/documents'

const inputDocument = parse(/* GraphQL */ `
  query A {
    ... on Query {
      a {
        ...B
        b
      }
    }
    ... on Query {
      a {
        ...B
        a
      }
    }
  }

  fragment B on Query {
    c
  }
`)
const outputStr = printExecutableGraphQLDocument(inputDocument)
console.assert(
  outputStr ===
    'fragment B on Query { c } query A { ... on Query { a { a ...B } } ... on Query { a { b ...B } } }',
  'Stuff is not equal.'
)

Rules

  • Fragments are always printed before executable operations
  • Executable operations are sorted alphabetically by name.
  • Arguments (Directive, Fields) are sorted alphabetical
  • Selections sets are sorted Field, FragmentSpread, InlineFragmentSpread (sorted based on TypeCondition, inner SelectionSet)

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

3 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |