1.5.0 • Published 5 years ago
@jenyus-org/graphql-utils v1.5.0
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-utilsYarn:
yarn add @jenyus-org/graphql-utilsThis 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
}
}
}