Getting Started
GraphQL-Utils is a lightweight library built to work with the GraphQL AST to supercharge your GraphQL APIs. Unlike other offerings out there, we don't just parse the AST to an object map, or array of strings, but offer utilities to make working with the AST even easier than ever before.
#
InstallationGraphQL-Utils can be installed with npm
:
Or yarn
:
#
UsageOne of the most straightforward and common use-cases of GraphQL-Utils is checking if a query contains a certain path. We can do this using the hasFields()
utility:
QueryLive
Code
Output
tip
You can edit the query in the editor above to get a feel for how GraphQL-Utils works.
Using this technique, we can, for example, conditionally JOIN
our post authors only when requested using a query builder like KnexJS or ORMs such as MikroORM.
#
Typescript SupportGraphQL-Utils is built with Typescript and exports declaration files so you will get stellar type-hinting including some types built into GraphQL-Utils.