npm.io
1.0.6 • Published 7 years ago

graphql-prettier

Licence
MIT
Version
1.0.6
Deps
1
Size
11 kB
Vulns
0
Weekly
0
Stars
2

GraphQL Prettier Codacy Badge Codacy Badge Build Status

Prettify & simplify GraphQL query/mutation/subscription.

Description

Package exports a default function which accepts two parameters:

prettify(source: string, noDuplicates = true): string

source is a string with GraphQL query/mutation/subscription to prettify

noDuplicates is a boolean value which set up to false turns out function to leaving duplicated fields

Install

npm install graphql-prettier

Usage

import gqlPrettier from 'graphql-prettier';

const query = `
query ViewerQuery {
  viewer {
    user {
      id
      name
      ...userFragment
    }
  }
}
fragment userFragment on User {
  id
  name
  email
}
`;

const prettifiedQuery = gqlPrettier(query); // returns string

Example

query ViewerQuery {
  viewer {
    user {
      id
      name
      id
      ...userFragment
      name
    }
  }
}
fragment userFragment on User {
  id
  name
  email
  name
}

Is transformed to:

query ViewerQuery {
  viewer {
    user {
      id
      name
      email
    }
  }
}
License

GraphQL Prettier is MIT-licensed.

Keywords