Prettify & simplify GraphQL query/mutation/subscription.
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 the function to not removing duplicated fields
npm install graphql-prettier
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
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
}
}
}
GraphQL Prettier is MIT-licensed.