graphql-prettier
v1.0.6
Published
Prettify & simplify GraphQL query/mutation/subscription.
Downloads
16,264
Maintainers
Readme
GraphQL Prettier
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.