1.9.3 • Published 3 years ago

graphql-query-vars-cleaner v1.9.3

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

Remove undefined variables from GraphQL queries.

Why?

Having a large number of undefined variables in a GraphQL can hurt performance on some backends. For a query backing a table, you might have a filter and an order variable for each column. Often it is easier to leave these variables as undefined, so instead graphql-query-vars-cleaner will filter out these undefined variables.

Installation

yarn add graphql-query-vars-cleaner
npm install graphql-query-vars-cleaner

Note:
GraphQL is a peer dependency. To run, also install graphql:
Yarn: yarn add graphql
NPM: npm install graphql

API

import { getQuery } from "graphql-query-vars-cleaner";

const query = `
query ($var1: Int, $var2: Int) {
  field(where: $var1, and: $var2) {
    x
    y
  }
}`;

const variables = {
  var1: 1
};

console.log(getQuery(query, variables));

// Output:
// query ($var1: Int) { field (where: $var1) { x y } }

Types

import { getQuery, Variables } from "graphql-query-vars-cleaner";

function getQuery(query: string, variables?: Variables): string

type Variables = {
  [name: string]: string | undefined;
}
  • graphql-tag: A JavaScript template literal tag that parses GraphQL queries
  • is-obj-empty: Check if an object is empty
  • json-to-graphql-query: This is a simple module that takes a JavaScript object and turns it into a GraphQL query to be sent to a GraphQL server.
  • @bconnorwhite/bob: Bob builds and watches typescript projects.
  • graphql: A Query Language and Runtime which can target any service.
  • jest: Delightful JavaScript Testing.
  • graphql: A Query Language and Runtime which can target any service.

MIT

1.9.3

3 years ago

1.9.2

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.0

4 years ago