@jenyus-org/graphql-utils
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

graphql-utils

License: MIT NPM Release NPM Downloads NPM Type Definitions

@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
    }
  }
}

Package Sidebar

Install

npm i @jenyus-org/graphql-utils

Weekly Downloads

2,462

Version

1.5.0

License

MIT

Unpacked Size

80.2 kB

Total Files

63

Last publish

Collaborators

  • dan6erbond
  • doemuu