0.0.2 • Published 6 years ago

is-graphql-document v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

is-graphql-document (deprecated)

(deprecated) I really think that you do not need this. ;)


Simple tool to check if given structure is graphQL document.

Install: npm install is-graphql-document

isGraphQLDocument

import isGraphQLDocument from 'is-graphql-document';

const query = gql`
  {
    happyFace(id: 42) {
      face
      happiness
    }
  }
`;

isGraphQLDocument(query); // true

isGraphQLDocument('something else'); // false

isGraphQLDocument('{ happyFace(id: 42) { face happiness }}'); // false

isGraphQLDocument(gql`{ happyFace(id: 42) { face happiness }}`); // true

isGraphQLDocumentStrict

Additionally you can use extended version that thoroughly check the object, but requires the whole graphql library, therefore it will add significantly to your bundle. Use specific import here.

import isGraphQLDocumentStrict from 'is-graphql-document/isGraphQLDocumentStrict';

const notGraphQLDoc = { kind: 'Document', definitions: [], loc: { start: 1, end: 1 } };


isValidGraphQlString(string); // true

isValidGraphQlString(stringInvalid); // false

Caveats

To make it fast we suppose that your input that is checked will be reasonably different from standard graphql document schema. This means that this:

{ kind: 'Document', definitions: [], loc: { start: 1, end: 1 } }

will be considered as graphQL document, if you will use standard version. In most cases it's sufficient. If not use strict version.

Feedback

Feedback and PRs are welcome. Please, take into account that the main reason is to have very lightweight tool with minimal (default) dependencies.

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago