New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

graphql-optimize-query

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-optimize-query

[![npm version](https://badge.fury.io/js/graphql-optimize-query.svg)](https://badge.fury.io/js/graphql-optimize-query)

latest
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

graphql-optimize-query

npm version

A lightweight library to optimize graphql queries by evaluating @include and @skip directives client-side.

Usage

Install graphql-optimize-query from npm with:

npm install graphql-optimize-query

Import with:

const { optimizeQuery } = require('graphql-optimize-query')
// or
import { optimizeQuery } from 'graphql-optimize-query';

Example

const { print } = require('graphql');
const gql = require('graphql-tag');
const { optimizeQuery } = require('graphql-optimize-query');

const query = gql`
  query GetUser($userID: ID!, $auth: Boolean!) {
    user(id: $userID) {
      name @include(if: $auth) {
        firstName
        lastName
      }
      ... on Asset @include(if: $auth) {
        data
      }
      other
    }
  }
`;

const editedAST = optimizeQuery(query, { auth: false });

console.log(print(editedAST));

Expected output

query GetUser($userID: ID!) {
  user(id: $userID) {
    other
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details

FAQs

Package last updated on 06 Jul 2021

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