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

apollo-link-persisted-queries

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-persisted-queries - npm Package Compare versions

Comparing version 0.0.1-beta.3 to 0.1.0

3

CHANGELOG.md

@@ -5,2 +5,5 @@ # Change log

### 0.1.0
- handle network errors correctly for 400 and 500
### 0.0.1-beta.3

@@ -7,0 +10,0 @@ - change default error handling to only disable on 400 error, not >= 500

94

lib/bundle.umd.js

@@ -7,19 +7,2 @@ (function (global, factory) {

var __assign = (undefined && undefined.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __rest = (undefined && undefined.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var sha256 = require('hash.js/lib/hash/sha/256');

@@ -34,12 +17,15 @@ var VERSION = 1;

generateHash: defaultGenerateHash,
disable: function (_a, _b) {
var errors = _a.errors;
var response = _b.response;
if (errors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotSupported';
})) {
disable: function (_a) {
var graphQLErrors = _a.graphQLErrors, operation = _a.operation;
if (graphQLErrors &&
graphQLErrors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotSupported';
})) {
return true;
}
if (response && response.statusCode && response.statusCode === 400) {
var response = operation.getContext().response;
if (response &&
response.status &&
(response.status === 400 || response.status === 500)) {
return true;

@@ -79,29 +65,41 @@ }

var subscription;
var tried = false;
var handler = {
next: function (_a) {
var data = _a.data, errors = _a.errors, rest = __rest(_a, ["data", "errors"]);
if (!tried && errors) {
tried = true;
supportsPersistedQueries = !disable(__assign({ data: data, errors: errors }, rest), operation.getContext());
if (errors.some(function (_a) {
var retried = false;
var retry = function (_a, cb) {
var response = _a.response, networkError = _a.networkError;
if ((!retried && (response && response.errors)) || networkError) {
retried = true;
var disablePayload = {
response: response,
networkError: networkError,
operation: operation,
graphQLErrors: response ? response.errors : null,
};
supportsPersistedQueries = !disable(disablePayload);
if ((response &&
response.errors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotFound';
}) ||
!supportsPersistedQueries) {
if (subscription)
subscription.unsubscribe();
operation.setContext({
http: {
includeQuery: true,
includeExtensions: supportsPersistedQueries,
},
});
subscription = forward(operation).subscribe(handler);
return;
}
})) ||
!supportsPersistedQueries) {
if (subscription)
subscription.unsubscribe();
operation.setContext({
http: {
includeQuery: true,
includeExtensions: supportsPersistedQueries,
},
});
subscription = forward(operation).subscribe(handler);
return;
}
observer.next(__assign({ data: data, errors: errors }, rest));
}
cb();
};
var handler = {
next: function (response) {
retry({ response: response }, function () { return observer.next(response); });
},
error: observer.error.bind(observer),
error: function (networkError) {
retry({ networkError: networkError }, function () { return observer.error(networkError); });
},
complete: observer.complete.bind(observer),

@@ -108,0 +106,0 @@ };

@@ -1,16 +0,18 @@

import { ApolloLink } from 'apollo-link';
import { ExecutionResult } from 'graphql';
import { ApolloLink, Operation } from 'apollo-link';
import { ExecutionResult, GraphQLError } from 'graphql';
export declare const VERSION = 1;
export interface ErrorResponse {
graphQLErrors?: GraphQLError[];
networkError?: Error;
response?: ExecutionResult;
operation: Operation;
}
export declare const defaultGenerateHash: (query: any) => any;
export declare const defaultOptions: {
generateHash: (query: any) => any;
disable: ({errors}: {
errors: any;
}, {response}: {
response: any;
}) => boolean;
disable: ({graphQLErrors, operation}: ErrorResponse) => boolean;
};
export declare const createPersistedQueryLink: ({generateHash, disable}?: {
generateHash?: (DocumentNode: any) => string;
disable?: (result: ExecutionResult, context: any) => boolean;
disable?: (error: ErrorResponse) => boolean;
}) => ApolloLink;

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

var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
import { ApolloLink, Observable } from 'apollo-link';

@@ -29,12 +12,15 @@ var sha256 = require('hash.js/lib/hash/sha/256');

generateHash: defaultGenerateHash,
disable: function (_a, _b) {
var errors = _a.errors;
var response = _b.response;
if (errors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotSupported';
})) {
disable: function (_a) {
var graphQLErrors = _a.graphQLErrors, operation = _a.operation;
if (graphQLErrors &&
graphQLErrors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotSupported';
})) {
return true;
}
if (response && response.statusCode && response.statusCode === 400) {
var response = operation.getContext().response;
if (response &&
response.status &&
(response.status === 400 || response.status === 500)) {
return true;

@@ -74,29 +60,41 @@ }

var subscription;
var tried = false;
var handler = {
next: function (_a) {
var data = _a.data, errors = _a.errors, rest = __rest(_a, ["data", "errors"]);
if (!tried && errors) {
tried = true;
supportsPersistedQueries = !disable(__assign({ data: data, errors: errors }, rest), operation.getContext());
if (errors.some(function (_a) {
var retried = false;
var retry = function (_a, cb) {
var response = _a.response, networkError = _a.networkError;
if ((!retried && (response && response.errors)) || networkError) {
retried = true;
var disablePayload = {
response: response,
networkError: networkError,
operation: operation,
graphQLErrors: response ? response.errors : null,
};
supportsPersistedQueries = !disable(disablePayload);
if ((response &&
response.errors.some(function (_a) {
var message = _a.message;
return message === 'PersistedQueryNotFound';
}) ||
!supportsPersistedQueries) {
if (subscription)
subscription.unsubscribe();
operation.setContext({
http: {
includeQuery: true,
includeExtensions: supportsPersistedQueries,
},
});
subscription = forward(operation).subscribe(handler);
return;
}
})) ||
!supportsPersistedQueries) {
if (subscription)
subscription.unsubscribe();
operation.setContext({
http: {
includeQuery: true,
includeExtensions: supportsPersistedQueries,
},
});
subscription = forward(operation).subscribe(handler);
return;
}
observer.next(__assign({ data: data, errors: errors }, rest));
}
cb();
};
var handler = {
next: function (response) {
retry({ response: response }, function () { return observer.next(response); });
},
error: observer.error.bind(observer),
error: function (networkError) {
retry({ networkError: networkError }, function () { return observer.error(networkError); });
},
complete: observer.complete.bind(observer),

@@ -103,0 +101,0 @@ };

{
"name": "apollo-link-persisted-queries",
"version": "0.0.1-beta.3",
"version": "0.1.0",
"description": "Use persisted queries with Apollo Link",

@@ -5,0 +5,0 @@ "author": "James Baxley <james@meteor.com>",

@@ -41,4 +41,13 @@ Automatic Persisted Queries

- `generateHash`: a function that takes the query document and returns the hash. If not provided, `generateHash` defaults to a fast implementation of sha256 + hex digest.
- `disable`: a function which takes the response and context (typically including the fetch response as `response`) and returns a boolean to disable any future persited queries for that session. This defaults to disabling on `PersistedQueryNotSupported` or a 500 or greater status code
- `disable`: a function which takes an ErrorResponse (see below) and returns a boolean to disable any future persited queries for that session. This defaults to disabling on `PersistedQueryNotSupported` or a 400 or 500 http error
**ErrorResponse**
The arugment that the optional `disable` function is given is an object with the following keys:
- `operation`: The Operation that errored (contains query, variables, operationName, and context)
- `response`: The Execution of the reponse (contains data and errors as well extensions if sent from the server)
- `graphQLErrors`: An array of errors from the GraphQL endpoint
- `networkError`: any error during the link execution or server response
*Note*: `networkError` is the value from the downlink's `error` callback. In most cases, `graphQLErrors` is the `errors` field of the result from the last `next` call. A `networkError` can contain additional fields, such as a GraphQL object in the case of a failing HTTP status code from `apollo-link-http`. In this situation, `graphQLErrors` is an alias for `networkError.result.errors` if the property exists.
## Apollo Engine

@@ -45,0 +54,0 @@ Apollo Engine supports recieving and fulfulling Automatic Persisted Queries. Simply adding this link into your client app will improve your network response times when using Apollo Engine.

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