1. @graphql-tools/documents
Utilities for GraphQL documents.
@graphql-tools/documents
Package: @graphql-tools/documents
Created by: ardatan
Last modified: Fri, 19 May 2023 10:56:25 GMT
Version: 1.0.0
License: MIT
Downloads: 4,532,188
Repository: https://github.com/ardatan/graphql-tools

Install

npm install @graphql-tools/documents
yarn add @graphql-tools/documents

@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)

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin