Socket
Book a DemoInstallSign in
Socket

@jumpn/utils-graphql

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jumpn/utils-graphql

GraphQL utilities

0.4.1
Source
npmnpm
Version published
Weekly downloads
33K
-19.24%
Maintainers
2
Weekly downloads
 
Created
Source

@jumpn/utils-graphql

GraphQL utilities

  • Installation
  • Types
  • API
  • License

Installation

Using npm

$ npm install --save @jumpn/utils-graphql

Using yarn

$ yarn add @jumpn/utils-graphql

Types

export type {DocumentNode} from "graphql/language/ast";

type GqlErrorLocation = {
  line: number,
  column: number
};

type GqlError = {
  message: string,
  locations?: Array<GqlErrorLocation>
};

type GqlRequest<Variables: void | Object = void> = {
  operation: string,
  variables?: Variables
};

type GqlResponse<Data> = {
  data?: Data,
  errors?: Array<GqlError>
};

type GqlOperationType = "mutation" | "query" | "subscription";

API

errorsToString

Transforms an array of GqlError into a string.

Parameters

  • gqlErrors Array<GqlError>

Examples

const gqlRespose = {
  errors: [
    {message: "First Error", locations: [{column: 10, line: 2}]},
    {message: "Second Error", locations: [{column: 2, line: 4}]}
  ]
}

const error = errorsToString(gqlRespose.errors);
// string with the following:
// First Error (2:10)
// Second Error (4:2)

Returns string

getOperationType

Returns the type (query, mutation, or subscription) of the given operation

Parameters

Examples

const operation = `
  subscription userSubscription($userId: ID!) {
    user(userId: $userId) {
      id
      name
    }
  }
`;

const operationType = getOperationType(operation);

console.log(operationType); // "subscription"

Returns GqlOperationType

hasSubscription

Returns true if documentNode has a subscription or false otherwise

Parameters

  • documentNode DocumentNode

Returns boolean

License

MIT :copyright: Jumpn Limited / Mauro Titimoli (mauro@jumpn.com)

Keywords

flow

FAQs

Package last updated on 01 Nov 2017

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.