@jenyus-org/graphql-utils
v1.5.0
Published
GraphQL utilities to make working with GraphQL queries and APIs simpler.
Downloads
31,279
Readme
graphql-utils
@jenyus-org/graphql-utils
is a collection of utilities to aid in working with GraphQL projects that have the graphql
library as a base.
Documentation
The full documentation with live code sandboxes can be found here.
Installation
@jenyus-org/graphql-utils
can be installed from NPM by running one of the following commands:
NPM:
npm i --save @jenyus-org/graphql-utils
Yarn:
yarn add @jenyus-org/graphql-utils
This will install @jenyus-org/graphql-utils
and all its dependencies.
Getting Started
One 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:
import { hasFields } from "@jenyus-org/graphql-utils";
const resolvers = {
Query: {
posts(_, __, ___, info) {
const requestedAuthor = hasFields(info, "posts.author");
console.log(requestedAuthor);
},
},
};
This will output true
for the following query:
{
posts {
id
title
body
author {
id
username
firstName
lastName
}
}
}