🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

apollo-utilities

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
a

apollo-utilities

Utilities for working with GraphQL ASTs

1.3.4
latest
97

Supply Chain Security

100

Vulnerability

72

Quality

81

Maintenance

100

License

Version published
Weekly downloads
1.1M
-8.31%
Maintainers
4
Weekly downloads
 
Created
Issues
534

What is apollo-utilities?

The apollo-utilities package provides a set of utility functions for working with GraphQL data in Apollo Client. These utilities help with tasks such as parsing, transforming, and comparing GraphQL queries and results.

What are apollo-utilities's main functionalities?

GraphQL Query Parsing

This feature allows you to parse a GraphQL query and extract the operation definition. The code sample demonstrates how to use the `getOperationDefinition` function to parse a query and log the operation definition.

const { getOperationDefinition } = require('apollo-utilities');
const gql = require('graphql-tag');

const query = gql`
  query GetUser {
    user(id: 1) {
      id
      name
    }
  }
`;

const operationDefinition = getOperationDefinition(query);
console.log(operationDefinition);

Deep Equality Check

This feature provides a deep equality check for comparing two objects. The code sample demonstrates how to use the `isEqual` function to compare two nested objects.

const { isEqual } = require('apollo-utilities');

const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } };

console.log(isEqual(obj1, obj2)); // true

Query Transformation

This feature allows you to transform a GraphQL query by adding `__typename` fields to it. The code sample demonstrates how to use the `addTypenameToDocument` function to transform a query.

const { addTypenameToDocument } = require('apollo-utilities');
const gql = require('graphql-tag');

const query = gql`
  query GetUser {
    user(id: 1) {
      id
      name
    }
  }
`;

const transformedQuery = addTypenameToDocument(query);
console.log(transformedQuery);

Other packages similar to apollo-utilities

FAQs

Package last updated on 09 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts