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

apollo-link-http

Package Overview
Dependencies
Maintainers
3
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-http - npm Package Compare versions

Comparing version 1.5.3 to 1.5.4

4

CHANGELOG.md

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

### 1.5.4
- Update apollo-link [#559](https://github.com/apollographql/apollo-link/pull/559)
- Check for signal already present on `fetchOptions` [#584](https://github.com/apollographql/apollo-link/pull/584)
### 1.5.3

@@ -7,0 +11,0 @@ - updated dependency on `apolloLink.httpCommon` [#522](https://github.com/apollographql/apollo-link/pull/522)

326

lib/bundle.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link'), require('apollo-link-http-common')) :
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link', 'apollo-link-http-common'], factory) :
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.http = {}),global.apolloLink.core,global.apolloLink.httpCommon));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link'), require('apollo-link-http-common')) :
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link', 'apollo-link-http-common'], factory) :
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.http = {}),global.apolloLink.core,global.apolloLink.httpCommon));
}(this, (function (exports,apolloLink,apolloLinkHttpCommon) { 'use strict';
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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 __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 createHttpLink = function (linkOptions) {
if (linkOptions === void 0) { linkOptions = {}; }
var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, requestOptions = __rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries"]);
apolloLinkHttpCommon.checkFetcher(fetcher);
if (!fetcher) {
fetcher = fetch;
}
var linkConfig = {
http: { includeExtensions: includeExtensions },
options: requestOptions.fetchOptions,
credentials: requestOptions.credentials,
headers: requestOptions.headers,
var createHttpLink = function (linkOptions) {
if (linkOptions === void 0) { linkOptions = {}; }
var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a,
// use default global fetch is nothing passed in
fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, requestOptions = __rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries"]);
// dev warnings to ensure fetch is present
apolloLinkHttpCommon.checkFetcher(fetcher);
//fetcher is set here rather than the destructuring to ensure fetch is
//declared before referencing it. Reference in the destructuring would cause
//a ReferenceError
if (!fetcher) {
fetcher = fetch;
}
var linkConfig = {
http: { includeExtensions: includeExtensions },
options: requestOptions.fetchOptions,
credentials: requestOptions.credentials,
headers: requestOptions.headers,
};
return new apolloLink.ApolloLink(function (operation) {
var chosenURI = apolloLinkHttpCommon.selectURI(operation, uri);
var context = operation.getContext();
var contextConfig = {
http: context.http,
options: context.fetchOptions,
credentials: context.credentials,
headers: context.headers,
};
//uses fallback, link, and then context to build options
var _a = apolloLinkHttpCommon.selectHttpOptionsAndBody(operation, apolloLinkHttpCommon.fallbackHttpConfig, linkConfig, contextConfig), options = _a.options, body = _a.body;
var controller;
if (!options.signal) {
var _b = apolloLinkHttpCommon.createSignalIfSupported(), _controller = _b.controller, signal = _b.signal;
controller = _controller;
if (controller)
options.signal = signal;
}
// If requested, set method to GET if there are no mutations.
var definitionIsMutation = function (d) {
return d.kind === 'OperationDefinition' && d.operation === 'mutation';
};
if (useGETForQueries &&
!operation.query.definitions.some(definitionIsMutation)) {
options.method = 'GET';
}
if (options.method === 'GET') {
var _c = rewriteURIForGET(chosenURI, body), newURI = _c.newURI, parseError = _c.parseError;
if (parseError) {
return apolloLink.fromError(parseError);
}
chosenURI = newURI;
}
else {
try {
options.body = apolloLinkHttpCommon.serializeFetchParameter(body, 'Payload');
}
catch (parseError) {
return apolloLink.fromError(parseError);
}
}
return new apolloLink.Observable(function (observer) {
fetcher(chosenURI, options)
.then(function (response) {
operation.setContext({ response: response });
return response;
})
.then(apolloLinkHttpCommon.parseAndCheckHttpResponse(operation))
.then(function (result) {
// we have data and can send it to back up the link chain
observer.next(result);
observer.complete();
return result;
})
.catch(function (err) {
// fetch was cancelled so its already been cleaned up in the unsubscribe
if (err.name === 'AbortError')
return;
// if it is a network error, BUT there is graphql result info
// fire the next observer before calling error
// this gives apollo-client (and react-apollo) the `graphqlErrors` and `networErrors`
// to pass to UI
// this should only happen if we *also* have data as part of the response key per
// the spec
if (err.result && err.result.errors && err.result.data) {
// if we dont' call next, the UI can only show networkError because AC didn't
// get andy graphqlErrors
// this is graphql execution result info (i.e errors and possibly data)
// this is because there is no formal spec how errors should translate to
// http status codes. So an auth error (401) could have both data
// from a public field, errors from a private field, and a status of 401
// {
// user { // this will have errors
// firstName
// }
// products { // this is public so will have data
// cost
// }
// }
//
// the result of above *could* look like this:
// {
// data: { products: [{ cost: "$10" }] },
// errors: [{
// message: 'your session has timed out',
// path: []
// }]
// }
// status code of above would be a 401
// in the UI you want to show data where you can, errors as data where you can
// and use correct http status codes
observer.next(err.result);
}
observer.error(err);
});
return function () {
// XXX support canceling this request
// https://developers.google.com/web/updates/2017/09/abortable-fetch
if (controller)
controller.abort();
};
});
});
};
return new apolloLink.ApolloLink(function (operation) {
var chosenURI = apolloLinkHttpCommon.selectURI(operation, uri);
var context = operation.getContext();
var contextConfig = {
http: context.http,
options: context.fetchOptions,
credentials: context.credentials,
headers: context.headers,
// For GET operations, returns the given URI rewritten with parameters, or a
// parse error.
function rewriteURIForGET(chosenURI, body) {
// Implement the standard HTTP GET serialization, plus 'extensions'. Note
// the extra level of JSON serialization!
var queryParams = [];
var addQueryParam = function (key, value) {
queryParams.push(key + "=" + encodeURIComponent(value));
};
var _a = apolloLinkHttpCommon.selectHttpOptionsAndBody(operation, apolloLinkHttpCommon.fallbackHttpConfig, linkConfig, contextConfig), options = _a.options, body = _a.body;
var _b = apolloLinkHttpCommon.createSignalIfSupported(), controller = _b.controller, signal = _b.signal;
if (controller)
options.signal = signal;
var definitionIsMutation = function (d) {
return d.kind === 'OperationDefinition' && d.operation === 'mutation';
};
if (useGETForQueries &&
!operation.query.definitions.some(definitionIsMutation)) {
options.method = 'GET';
if ('query' in body) {
addQueryParam('query', body.query);
}
if (options.method === 'GET') {
var _c = rewriteURIForGET(chosenURI, body), newURI = _c.newURI, parseError = _c.parseError;
if (parseError) {
return apolloLink.fromError(parseError);
if (body.operationName) {
addQueryParam('operationName', body.operationName);
}
if (body.variables) {
var serializedVariables = void 0;
try {
serializedVariables = apolloLinkHttpCommon.serializeFetchParameter(body.variables, 'Variables map');
}
chosenURI = newURI;
catch (parseError) {
return { parseError: parseError };
}
addQueryParam('variables', serializedVariables);
}
else {
if (body.extensions) {
var serializedExtensions = void 0;
try {
options.body = apolloLinkHttpCommon.serializeFetchParameter(body, 'Payload');
serializedExtensions = apolloLinkHttpCommon.serializeFetchParameter(body.extensions, 'Extensions map');
}
catch (parseError) {
return apolloLink.fromError(parseError);
return { parseError: parseError };
}
addQueryParam('extensions', serializedExtensions);
}
return new apolloLink.Observable(function (observer) {
fetcher(chosenURI, options)
.then(function (response) {
operation.setContext({ response: response });
return response;
})
.then(apolloLinkHttpCommon.parseAndCheckHttpResponse(operation))
.then(function (result) {
observer.next(result);
observer.complete();
return result;
})
.catch(function (err) {
if (err.name === 'AbortError')
return;
if (err.result && err.result.errors && err.result.data) {
observer.next(err.result);
}
observer.error(err);
});
return function () {
if (controller)
controller.abort();
};
});
});
};
function rewriteURIForGET(chosenURI, body) {
var queryParams = [];
var addQueryParam = function (key, value) {
queryParams.push(key + "=" + encodeURIComponent(value));
};
if ('query' in body) {
addQueryParam('query', body.query);
}
if (body.operationName) {
addQueryParam('operationName', body.operationName);
}
if (body.variables) {
var serializedVariables = void 0;
try {
serializedVariables = apolloLinkHttpCommon.serializeFetchParameter(body.variables, 'Variables map');
// Reconstruct the URI with added query params.
// XXX This assumes that the URI is well-formed and that it doesn't
// already contain any of these query params. We could instead use the
// URL API and take a polyfill (whatwg-url@6) for older browsers that
// don't support URLSearchParams. Note that some browsers (and
// versions of whatwg-url) support URL but not URLSearchParams!
var fragment = '', preFragment = chosenURI;
var fragmentStart = chosenURI.indexOf('#');
if (fragmentStart !== -1) {
fragment = chosenURI.substr(fragmentStart);
preFragment = chosenURI.substr(0, fragmentStart);
}
catch (parseError) {
return { parseError: parseError };
}
addQueryParam('variables', serializedVariables);
var queryParamsPrefix = preFragment.indexOf('?') === -1 ? '?' : '&';
var newURI = preFragment + queryParamsPrefix + queryParams.join('&') + fragment;
return { newURI: newURI };
}
if (body.extensions) {
var serializedExtensions = void 0;
try {
serializedExtensions = apolloLinkHttpCommon.serializeFetchParameter(body.extensions, 'Extensions map');
var HttpLink = /** @class */ (function (_super) {
__extends(HttpLink, _super);
function HttpLink(opts) {
return _super.call(this, createHttpLink(opts).request) || this;
}
catch (parseError) {
return { parseError: parseError };
}
addQueryParam('extensions', serializedExtensions);
}
var fragment = '', preFragment = chosenURI;
var fragmentStart = chosenURI.indexOf('#');
if (fragmentStart !== -1) {
fragment = chosenURI.substr(fragmentStart);
preFragment = chosenURI.substr(0, fragmentStart);
}
var queryParamsPrefix = preFragment.indexOf('?') === -1 ? '?' : '&';
var newURI = preFragment + queryParamsPrefix + queryParams.join('&') + fragment;
return { newURI: newURI };
}
var HttpLink = (function (_super) {
__extends(HttpLink, _super);
function HttpLink(opts) {
return _super.call(this, createHttpLink(opts).request) || this;
}
return HttpLink;
}(apolloLink.ApolloLink));
return HttpLink;
}(apolloLink.ApolloLink));
exports.createHttpLink = createHttpLink;
exports.HttpLink = HttpLink;
exports.createHttpLink = createHttpLink;
exports.HttpLink = HttpLink;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=bundle.umd.js.map

@@ -7,2 +7,7 @@ import { ApolloLink, RequestHandler } from 'apollo-link';

interface Options extends HttpOptions {
/**
* If set to true, use the HTTP GET method for query operations. Mutations
* will still use the method specified in fetchOptions.method (which defaults
* to POST).
*/
useGETForQueries?: boolean;

@@ -9,0 +14,0 @@ }

@@ -24,4 +24,10 @@ var __extends = (this && this.__extends) || (function () {

if (linkOptions === void 0) { linkOptions = {}; }
var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, requestOptions = __rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries"]);
var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a,
// use default global fetch is nothing passed in
fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, requestOptions = __rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries"]);
// dev warnings to ensure fetch is present
checkFetcher(fetcher);
//fetcher is set here rather than the destructuring to ensure fetch is
//declared before referencing it. Reference in the destructuring would cause
//a ReferenceError
if (!fetcher) {

@@ -45,6 +51,12 @@ fetcher = fetch;

};
//uses fallback, link, and then context to build options
var _a = selectHttpOptionsAndBody(operation, fallbackHttpConfig, linkConfig, contextConfig), options = _a.options, body = _a.body;
var _b = createSignalIfSupported(), controller = _b.controller, signal = _b.signal;
if (controller)
options.signal = signal;
var controller;
if (!options.signal) {
var _b = createSignalIfSupported(), _controller = _b.controller, signal = _b.signal;
controller = _controller;
if (controller)
options.signal = signal;
}
// If requested, set method to GET if there are no mutations.
var definitionIsMutation = function (d) {

@@ -80,2 +92,3 @@ return d.kind === 'OperationDefinition' && d.operation === 'mutation';

.then(function (result) {
// we have data and can send it to back up the link chain
observer.next(result);

@@ -86,5 +99,38 @@ observer.complete();

.catch(function (err) {
// fetch was cancelled so its already been cleaned up in the unsubscribe
if (err.name === 'AbortError')
return;
// if it is a network error, BUT there is graphql result info
// fire the next observer before calling error
// this gives apollo-client (and react-apollo) the `graphqlErrors` and `networErrors`
// to pass to UI
// this should only happen if we *also* have data as part of the response key per
// the spec
if (err.result && err.result.errors && err.result.data) {
// if we dont' call next, the UI can only show networkError because AC didn't
// get andy graphqlErrors
// this is graphql execution result info (i.e errors and possibly data)
// this is because there is no formal spec how errors should translate to
// http status codes. So an auth error (401) could have both data
// from a public field, errors from a private field, and a status of 401
// {
// user { // this will have errors
// firstName
// }
// products { // this is public so will have data
// cost
// }
// }
//
// the result of above *could* look like this:
// {
// data: { products: [{ cost: "$10" }] },
// errors: [{
// message: 'your session has timed out',
// path: []
// }]
// }
// status code of above would be a 401
// in the UI you want to show data where you can, errors as data where you can
// and use correct http status codes
observer.next(err.result);

@@ -95,2 +141,4 @@ }

return function () {
// XXX support canceling this request
// https://developers.google.com/web/updates/2017/09/abortable-fetch
if (controller)

@@ -102,3 +150,7 @@ controller.abort();

};
// For GET operations, returns the given URI rewritten with parameters, or a
// parse error.
function rewriteURIForGET(chosenURI, body) {
// Implement the standard HTTP GET serialization, plus 'extensions'. Note
// the extra level of JSON serialization!
var queryParams = [];

@@ -134,2 +186,8 @@ var addQueryParam = function (key, value) {

}
// Reconstruct the URI with added query params.
// XXX This assumes that the URI is well-formed and that it doesn't
// already contain any of these query params. We could instead use the
// URL API and take a polyfill (whatwg-url@6) for older browsers that
// don't support URLSearchParams. Note that some browsers (and
// versions of whatwg-url) support URL but not URLSearchParams!
var fragment = '', preFragment = chosenURI;

@@ -145,3 +203,3 @@ var fragmentStart = chosenURI.indexOf('#');

}
var HttpLink = (function (_super) {
var HttpLink = /** @class */ (function (_super) {
__extends(HttpLink, _super);

@@ -148,0 +206,0 @@ function HttpLink(opts) {

{
"name": "apollo-link-http",
"version": "1.5.3",
"version": "1.5.4",
"description": "HTTP transport layer for GraphQL",

@@ -42,4 +42,4 @@ "author": "Evans Hauser <evanshauser@gmail.com>",

"dependencies": {
"apollo-link": "^1.2.1",
"apollo-link-http-common": "^0.2.3"
"apollo-link": "^1.2.2",
"apollo-link-http-common": "^0.2.4"
},

@@ -50,21 +50,21 @@ "peerDependencies": {

"devDependencies": {
"@types/graphql": "0.12.4",
"@types/jest": "21.1.10",
"@types/graphql": "0.12.6",
"@types/jest": "22.2.2",
"apollo-fetch": "0.7.0",
"browserify": "16.1.0",
"browserify": "16.1.1",
"fetch-mock": "6.0.0",
"graphql": "0.13.1",
"graphql-tag": "2.7.3",
"jest": "21.2.1",
"graphql": "0.13.2",
"graphql-tag": "2.8.0",
"jest": "22.4.3",
"object-to-querystring": "1.0.8",
"rimraf": "2.6.1",
"rollup": "0.56.2",
"rollup": "0.57.1",
"ts-jest": "21.2.4",
"tslint": "5.9.1",
"typescript": "2.7.2",
"uglify-js": "3.3.11"
"uglify-js": "3.3.16"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
".(ts|tsx)": "ts-jest"
},

@@ -71,0 +71,0 @@ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",

@@ -80,4 +80,8 @@ import { ApolloLink, Observable, RequestHandler, fromError } from 'apollo-link';

const { controller, signal } = createSignalIfSupported();
if (controller) (options as any).signal = signal;
let controller;
if (!(options as any).signal) {
const { controller: _controller, signal } = createSignalIfSupported();
controller = _controller;
if (controller) (options as any).signal = signal;
}

@@ -84,0 +88,0 @@ // If requested, set method to GET if there are no mutations.

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