Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/graphql

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/graphql - npm Package Compare versions

Comparing version 4.6.4 to 4.7.0

32

dist-node/index.js

@@ -8,15 +8,19 @@ 'use strict';

const VERSION = "4.6.4";
const VERSION = "4.7.0";
class GraphqlError extends Error {
constructor(request, response) {
const message = response.data.errors[0].message;
super(message);
Object.assign(this, response.data);
Object.assign(this, {
headers: response.headers
});
this.name = "GraphqlError";
this.request = request; // Maintains proper stack trace (only available on V8)
function _buildMessageForResponseErrors(data) {
return `Request failed due to following response errors:\n` + data.errors.map(e => ` - ${e.message}`).join("\n");
}
class GraphqlResponseError extends Error {
constructor(request, headers, response) {
super(_buildMessageForResponseErrors(response));
this.request = request;
this.headers = headers;
this.response = response;
this.name = "GraphqlResponseError"; // Expose the errors and response data in their shorthand properties.
this.errors = response.errors;
this.data = response.data; // Maintains proper stack trace (only available on V8)
/* istanbul ignore next */

@@ -78,6 +82,3 @@

throw new GraphqlError(requestOptions, {
headers,
data: response.data
});
throw new GraphqlResponseError(requestOptions, headers, response.data);
}

@@ -116,4 +117,5 @@

exports.GraphqlResponseError = GraphqlResponseError;
exports.graphql = graphql$1;
exports.withCustomRequest = withCustomRequest;
//# sourceMappingURL=index.js.map

@@ -1,9 +0,15 @@

export class GraphqlError extends Error {
constructor(request, response) {
const message = response.data.errors[0].message;
super(message);
Object.assign(this, response.data);
Object.assign(this, { headers: response.headers });
this.name = "GraphqlError";
function _buildMessageForResponseErrors(data) {
return (`Request failed due to following response errors:\n` +
data.errors.map((e) => ` - ${e.message}`).join("\n"));
}
export class GraphqlResponseError extends Error {
constructor(request, headers, response) {
super(_buildMessageForResponseErrors(response));
this.request = request;
this.headers = headers;
this.response = response;
this.name = "GraphqlResponseError";
// Expose the errors and response data in their shorthand properties.
this.errors = response.errors;
this.data = response.data;
// Maintains proper stack trace (only available on V8)

@@ -10,0 +16,0 @@ /* istanbul ignore next */

@@ -1,2 +0,2 @@

import { GraphqlError } from "./error";
import { GraphqlResponseError } from "./error";
const NON_VARIABLE_OPTIONS = [

@@ -48,6 +48,3 @@ "method",

}
throw new GraphqlError(requestOptions, {
headers,
data: response.data,
});
throw new GraphqlResponseError(requestOptions, headers, response.data);
}

@@ -54,0 +51,0 @@ return response.data.data;

@@ -12,2 +12,3 @@ import { request } from "@octokit/request";

});
export { GraphqlResponseError } from "./error";
export function withCustomRequest(customRequest) {

@@ -14,0 +15,0 @@ return withDefaults(customRequest, {

@@ -1,1 +0,1 @@

export const VERSION = "4.6.4";
export const VERSION = "4.7.0";
import { ResponseHeaders } from "@octokit/types";
import { GraphQlEndpointOptions, GraphQlQueryResponse } from "./types";
export declare class GraphqlError<ResponseData> extends Error {
request: GraphQlEndpointOptions;
constructor(request: GraphQlEndpointOptions, response: {
headers: ResponseHeaders;
data: Required<GraphQlQueryResponse<ResponseData>>;
});
declare type ServerResponseData<T> = Required<GraphQlQueryResponse<T>>;
export declare class GraphqlResponseError<ResponseData> extends Error {
readonly request: GraphQlEndpointOptions;
readonly headers: ResponseHeaders;
readonly response: ServerResponseData<ResponseData>;
name: string;
readonly errors: GraphQlQueryResponse<never>["errors"];
readonly data: ResponseData;
constructor(request: GraphQlEndpointOptions, headers: ResponseHeaders, response: ServerResponseData<ResponseData>);
}
export {};
import { request } from "@octokit/request";
export declare const graphql: import("./types").graphql;
export { GraphQlQueryResponseData } from "./types";
export { GraphqlResponseError } from "./error";
export declare function withCustomRequest(customRequest: typeof request): import("./types").graphql;

@@ -1,1 +0,1 @@

export declare const VERSION = "4.6.4";
export declare const VERSION = "4.7.0";
import { request } from '@octokit/request';
import { getUserAgent } from 'universal-user-agent';
const VERSION = "4.6.4";
const VERSION = "4.7.0";
class GraphqlError extends Error {
constructor(request, response) {
const message = response.data.errors[0].message;
super(message);
Object.assign(this, response.data);
Object.assign(this, { headers: response.headers });
this.name = "GraphqlError";
function _buildMessageForResponseErrors(data) {
return (`Request failed due to following response errors:\n` +
data.errors.map((e) => ` - ${e.message}`).join("\n"));
}
class GraphqlResponseError extends Error {
constructor(request, headers, response) {
super(_buildMessageForResponseErrors(response));
this.request = request;
this.headers = headers;
this.response = response;
this.name = "GraphqlResponseError";
// Expose the errors and response data in their shorthand properties.
this.errors = response.errors;
this.data = response.data;
// Maintains proper stack trace (only available on V8)

@@ -68,6 +74,3 @@ /* istanbul ignore next */

}
throw new GraphqlError(requestOptions, {
headers,
data: response.data,
});
throw new GraphqlResponseError(requestOptions, headers, response.data);
}

@@ -103,3 +106,3 @@ return response.data.data;

export { graphql$1 as graphql, withCustomRequest };
export { GraphqlResponseError, graphql$1 as graphql, withCustomRequest };
//# sourceMappingURL=index.js.map
{
"name": "@octokit/graphql",
"description": "GitHub GraphQL API client for browsers and Node",
"version": "4.6.4",
"version": "4.7.0",
"license": "MIT",

@@ -30,7 +30,7 @@ "files": [

"@types/fetch-mock": "^7.2.5",
"@types/jest": "^26.0.0",
"@types/jest": "^27.0.0",
"@types/node": "^14.0.4",
"fetch-mock": "^9.0.0",
"jest": "^27.0.0",
"prettier": "2.3.1",
"prettier": "2.3.2",
"semantic-release": "^17.0.0",

@@ -37,0 +37,0 @@ "semantic-release-plugin-update-version-in-files": "^1.0.0",

@@ -266,6 +266,7 @@ # graphql.js

In case of a GraphQL error, `error.message` is set to the first error from the response’s `errors` array. All errors can be accessed at `error.errors`. `error.request` has the request options such as query, variables and headers set for easier debugging.
In case of a GraphQL error, `error.message` is set to a combined message describing all errors returned by the endpoint.
All errors can be accessed at `error.errors`. `error.request` has the request options such as query, variables and headers set for easier debugging.
```js
let { graphql } = require("@octokit/graphql");
let { graphql, GraphqlResponseError } = require("@octokit/graphql");
graphqlt = graphql.defaults({

@@ -285,16 +286,26 @@ headers: {

} catch (error) {
// server responds with
// {
// "data": null,
// "errors": [{
// "message": "Field 'bioHtml' doesn't exist on type 'User'",
// "locations": [{
// "line": 3,
// "column": 5
// }]
// }]
// }
if (error instanceof GraphqlResponseError) {
// do something with the error, allowing you to detect a graphql response error,
// compared to accidentally catching unrelated errors.
console.log("Request failed:", error.request); // { query, variables: {}, headers: { authorization: 'token secret123' } }
console.log(error.message); // Field 'bioHtml' doesn't exist on type 'User'
// server responds with an object like the following (as an example)
// class GraphqlResponseError {
// "headers": {
// "status": "403",
// },
// "data": null,
// "errors": [{
// "message": "Field 'bioHtml' doesn't exist on type 'User'",
// "locations": [{
// "line": 3,
// "column": 5
// }]
// }]
// }
console.log("Request failed:", error.request); // { query, variables: {}, headers: { authorization: 'token secret123' } }
console.log(error.message); // Field 'bioHtml' doesn't exist on type 'User'
} else {
// handle non-GraphQL error
}
}

@@ -301,0 +312,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc