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

apollo-link

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

9

CHANGELOG.md
# Change log
### vNEXT
- added support for a `fromPromise` to make it easy to create an observable from a promise fetcher
# 1.0.3
- removed requiring query on initial execution check
- moved to move efficent rollup build
# 1.0.1, 1.0.2
<!-- never published as latest -->
- preleases for dev tool integation
# 0.8.0

@@ -7,0 +14,0 @@ - added support for `extensions` on an operation

51

lib/bundle.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('zen-observable'), require('apollo-utilities'), require('graphql/language/printer')) :
typeof define === 'function' && define.amd ? define(['exports', 'zen-observable', 'apollo-utilities', 'graphql/language/printer'], factory) :
(factory((global.apolloLinkCore = {}),global.Observable,global.apolloUtilities,global.graphql_language_printer));
}(this, (function (exports,Observable,apolloUtilities,graphql_language_printer) { 'use strict';
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.core = {}),global.Observable,global.apollo.utilities,global.printer));
}(this, (function (exports,Observable,apolloUtilities,printer) { 'use strict';

@@ -33,4 +33,2 @@ var __extends = (undefined && undefined.__extends) || (function () {

];
if (!operation.query)
throw new Error('ApolloLink requires a query');
for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {

@@ -116,3 +114,3 @@ var key = _a[_i];

function getKey(operation) {
return graphql_language_printer.print(operation.query) + "|" + JSON.stringify(operation.variables) + "|" + operation.operationName;
return printer.print(operation.query) + "|" + JSON.stringify(operation.variables) + "|" + operation.operationName;
}

@@ -139,4 +137,4 @@

return test(operation)
? leftLink.execute(operation) || Observable.of()
: rightLink.execute(operation) || Observable.of();
? leftLink.request(operation) || Observable.of()
: rightLink.request(operation) || Observable.of();
});

@@ -147,4 +145,4 @@ }

return test(operation)
? leftLink.execute(operation, forward) || Observable.of()
: rightLink.execute(operation, forward) || Observable.of();
? leftLink.request(operation, forward) || Observable.of()
: rightLink.request(operation, forward) || Observable.of();
});

@@ -156,3 +154,3 @@ }

if (isTerminating(firstLink)) {
console.warn(new LinkError("You are calling concat on a terminating link, which will have no effect.\n Learn more about terminating links in the Apollo Link docs:\n https://www.apollographql.com/docs/link/overview.html#terminating", firstLink));
console.warn(new LinkError("You are calling concat on a terminating link, which will have no effect", firstLink));
return firstLink;

@@ -163,3 +161,3 @@ }

return new ApolloLink(function (operation) {
return firstLink.execute(operation, function (op) { return nextLink.execute(op) || Observable.of(); }) || Observable.of();
return firstLink.request(operation, function (op) { return nextLink.request(op) || Observable.of(); }) || Observable.of();
});

@@ -169,4 +167,4 @@ }

return new ApolloLink(function (operation, forward) {
return (firstLink.execute(operation, function (op) {
return nextLink.execute(op, forward) || Observable.of();
return (firstLink.request(operation, function (op) {
return nextLink.request(op, forward) || Observable.of();
}) || Observable.of());

@@ -178,5 +176,4 @@ });

function ApolloLink(request) {
if (request) {
if (request)
this.request = request;
}
}

@@ -193,26 +190,2 @@ ApolloLink.prototype.split = function (test, left, right) {

};
ApolloLink.prototype.notifyDevTools = function (operation, result) {
if (this.devToolsHook) {
this.devToolsHook({
network: {
operation: operation,
result: result,
},
});
}
};
ApolloLink.prototype.connectToDevTools = function (hook) {
if (!this.devToolsHook) {
this.devToolsHook = hook;
}
};
ApolloLink.prototype.execute = function (operation, forward) {
var _this = this;
return this.request(operation, forward).map(function (result) {
setTimeout(function () {
_this.notifyDevTools(operation, result);
}, 0);
return result;
});
};
ApolloLink.empty = empty;

@@ -219,0 +192,0 @@ ApolloLink.from = from;

@@ -9,3 +9,2 @@ /// <reference types="zen-observable" />

export declare class ApolloLink {
private devToolsHook;
constructor(request?: RequestHandler);

@@ -17,7 +16,4 @@ static empty: () => ApolloLink;

concat(next: ApolloLink | RequestHandler): ApolloLink;
request(operation: Operation, forward?: NextLink): Observable<FetchResult>;
private notifyDevTools(operation, result);
connectToDevTools(hook: Function): void;
execute(operation: Operation, forward?: NextLink): Observable<FetchResult>;
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
}
export declare function execute(link: ApolloLink, operation: GraphQLRequest): Observable<FetchResult>;

@@ -22,4 +22,4 @@ import * as Observable from 'zen-observable';

return test(operation)
? leftLink.execute(operation) || Observable.of()
: rightLink.execute(operation) || Observable.of();
? leftLink.request(operation) || Observable.of()
: rightLink.request(operation) || Observable.of();
});

@@ -30,4 +30,4 @@ }

return test(operation)
? leftLink.execute(operation, forward) || Observable.of()
: rightLink.execute(operation, forward) || Observable.of();
? leftLink.request(operation, forward) || Observable.of()
: rightLink.request(operation, forward) || Observable.of();
});

@@ -39,3 +39,3 @@ }

if (isTerminating(firstLink)) {
console.warn(new LinkError("You are calling concat on a terminating link, which will have no effect.\n Learn more about terminating links in the Apollo Link docs:\n https://www.apollographql.com/docs/link/overview.html#terminating", firstLink));
console.warn(new LinkError("You are calling concat on a terminating link, which will have no effect", firstLink));
return firstLink;

@@ -46,3 +46,3 @@ }

return new ApolloLink(function (operation) {
return firstLink.execute(operation, function (op) { return nextLink.execute(op) || Observable.of(); }) || Observable.of();
return firstLink.request(operation, function (op) { return nextLink.request(op) || Observable.of(); }) || Observable.of();
});

@@ -52,4 +52,4 @@ }

return new ApolloLink(function (operation, forward) {
return (firstLink.execute(operation, function (op) {
return nextLink.execute(op, forward) || Observable.of();
return (firstLink.request(operation, function (op) {
return nextLink.request(op, forward) || Observable.of();
}) || Observable.of());

@@ -61,5 +61,4 @@ });

function ApolloLink(request) {
if (request) {
if (request)
this.request = request;
}
}

@@ -76,26 +75,2 @@ ApolloLink.prototype.split = function (test, left, right) {

};
ApolloLink.prototype.notifyDevTools = function (operation, result) {
if (this.devToolsHook) {
this.devToolsHook({
network: {
operation: operation,
result: result,
},
});
}
};
ApolloLink.prototype.connectToDevTools = function (hook) {
if (!this.devToolsHook) {
this.devToolsHook = hook;
}
};
ApolloLink.prototype.execute = function (operation, forward) {
var _this = this;
return this.request(operation, forward).map(function (result) {
setTimeout(function () {
_this.notifyDevTools(operation, result);
}, 0);
return result;
});
};
ApolloLink.empty = empty;

@@ -102,0 +77,0 @@ ApolloLink.from = from;

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

];
if (!operation.query)
throw new Error('ApolloLink requires a query');
for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {

@@ -34,0 +32,0 @@ var key = _a[_i];

@@ -7,3 +7,3 @@ /// <reference types="zen-observable" />

constructor(handleRequest?: RequestHandler);
request(operation: Operation, forward?: NextLink): Observable<FetchResult>;
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
}

@@ -11,3 +11,2 @@ var __extends = (this && this.__extends) || (function () {

})();
import * as Observable from 'zen-observable';
import { ApolloLink } from '../link';

@@ -17,3 +16,3 @@ var MockLink = (function (_super) {

function MockLink(handleRequest) {
if (handleRequest === void 0) { handleRequest = function () { return Observable.of(); }; }
if (handleRequest === void 0) { handleRequest = function () { return null; }; }
var _this = _super.call(this) || this;

@@ -20,0 +19,0 @@ _this.request = handleRequest;

@@ -25,8 +25,2 @@ /// <reference types="zen-observable" />

export declare type NextLink = (operation: Operation) => Observable<FetchResult>;
export declare type RequestHandler = (operation: Operation, forward?: NextLink) => Observable<FetchResult>;
export declare type DevToolsMessage = {
network: {
operation: Operation;
result: FetchResult;
};
};
export declare type RequestHandler = (operation: Operation, forward?: NextLink) => Observable<FetchResult> | null;
{
"name": "apollo-link",
"version": "1.0.2",
"version": "1.0.3",
"description": "Flexible, lightweight transport layer for GraphQL",

@@ -27,3 +27,3 @@ "author": "Evans Hauser <evanshauser@gmail.com>",

"build:browser":
"browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-utilities --i graphql --i zen-observable-ts && npm run minify:browser",
"browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-utilities --i graphql --i zen-observable && npm run minify:browser",
"build": "tsc -p .",

@@ -45,3 +45,3 @@ "bundle": "rollup -c",

"@types/zen-observable": "0.5.3",
"apollo-utilities": "^1.0.1",
"apollo-utilities": "^1.0.0",
"zen-observable": "^0.6.0"

@@ -53,4 +53,4 @@ },

"devDependencies": {
"@types/graphql": "0.11.5",
"@types/jest": "21.1.5",
"@types/graphql": "0.11.6",
"@types/jest": "21.1.6",
"browserify": "14.5.0",

@@ -61,7 +61,7 @@ "graphql": "0.11.7",

"rimraf": "2.6.1",
"rollup": "0.45.2",
"ts-jest": "21.2.1",
"rollup": "0.51.5",
"ts-jest": "21.2.2",
"tslint": "5.8.0",
"typescript": "2.6.1",
"uglify-js": "3.1.8"
"uglify-js": "3.1.9"
},

@@ -68,0 +68,0 @@ "jest": {

@@ -1,17 +0,3 @@

export default {
entry: './lib/index.js',
dest: './lib/bundle.umd.js',
format: 'umd',
sourceMap: true,
moduleName: 'apolloLinkCore',
exports: 'named',
onwarn,
};
import build from '../../rollup.config';
function onwarn(message) {
const suppressed = ['UNRESOLVED_IMPORT', 'THIS_IS_UNDEFINED'];
if (!suppressed.find(code => message.code === code)) {
return console.warn(message.message);
}
}
export default build('core');

@@ -431,4 +431,3 @@ import * as Observable from 'zen-observable';

}).toEqual(op);
done();
return Observable.of();
return done();
}),

@@ -728,2 +727,32 @@ ]);

it("should return an empty observable when a concat'd link returns null", done => {
const link = new MockLink((operation, forward) => {
return forward(operation);
}).concat(() => null);
testLinkResults({
link,
results: [],
done,
});
});
it('should return an empty observable when a split link returns null', done => {
let context = { test: true };
const link = new SetContextLink(() => context).split(
op => op.getContext().test,
() => Observable.of(),
() => null,
);
testLinkResults({
link,
results: [],
});
context.test = false;
testLinkResults({
link,
results: [],
done,
});
});
it('should set a default context, variable, query and operationName on a copy of operation', done => {

@@ -730,0 +759,0 @@ const operation = {

@@ -10,10 +10,2 @@ import { validateOperation, fromPromise, makePromise } from '../linkUtils';

it('should throw when missing a query of some kind', () => {
expect(() =>
validateOperation(<any>{
query: '',
}),
).toThrow();
});
it('should not throw when valid fields in operation', () => {

@@ -20,0 +12,0 @@ expect(() =>

@@ -44,4 +44,4 @@ import * as Observable from 'zen-observable';

return test(operation)
? leftLink.execute(operation) || Observable.of()
: rightLink.execute(operation) || Observable.of();
? leftLink.request(operation) || Observable.of()
: rightLink.request(operation) || Observable.of();
});

@@ -51,4 +51,4 @@ } else {

return test(operation)
? leftLink.execute(operation, forward) || Observable.of()
: rightLink.execute(operation, forward) || Observable.of();
? leftLink.request(operation, forward) || Observable.of()
: rightLink.request(operation, forward) || Observable.of();
});

@@ -67,5 +67,3 @@ }

new LinkError(
`You are calling concat on a terminating link, which will have no effect.
Learn more about terminating links in the Apollo Link docs:
https://www.apollographql.com/docs/link/overview.html#terminating`,
`You are calling concat on a terminating link, which will have no effect`,
firstLink,

@@ -81,5 +79,5 @@ ),

operation =>
firstLink.execute(
firstLink.request(
operation,
op => nextLink.execute(op) || Observable.of(),
op => nextLink.request(op) || Observable.of(),
) || Observable.of(),

@@ -90,4 +88,4 @@ );

return (
firstLink.execute(operation, op => {
return nextLink.execute(op, forward) || Observable.of();
firstLink.request(operation, op => {
return nextLink.request(op, forward) || Observable.of();
}) || Observable.of()

@@ -100,14 +98,4 @@ );

export class ApolloLink {
private devToolsHook: Function;
constructor(request?: RequestHandler) {
if (request) {
this.request = request;
// if (request() === null) {
// throw new Error(`
// Your request handler must return an Observable.
// Visit the Apollo Link docs to learn more about request handlers:
// https://www.apollographql.com/docs/link/overview.html#request
// `);
// }
}
if (request) this.request = request;
}

@@ -134,35 +122,5 @@

forward?: NextLink,
): Observable<FetchResult> {
): Observable<FetchResult> | null {
throw new Error('request is not implemented');
}
private notifyDevTools(operation: Operation, result: FetchResult): void {
if (this.devToolsHook) {
this.devToolsHook({
network: {
operation,
result,
},
});
}
}
public connectToDevTools(hook: Function): void {
if (!this.devToolsHook) {
this.devToolsHook = hook;
}
}
public execute(
operation: Operation,
forward?: NextLink,
): Observable<FetchResult> {
return this.request(operation, forward).map(result => {
setTimeout(() => {
this.notifyDevTools(operation, result);
}, 0);
return result;
});
}
}

@@ -169,0 +127,0 @@

@@ -16,3 +16,2 @@ import { getOperationName } from 'apollo-utilities';

];
if (!operation.query) throw new Error('ApolloLink requires a query');
for (let key of Object.keys(operation)) {

@@ -19,0 +18,0 @@ if (OPERATION_FIELDS.indexOf(key) < 0) {

@@ -8,3 +8,3 @@ import { Operation, RequestHandler, NextLink, FetchResult } from '../types';

export default class MockLink extends ApolloLink {
constructor(handleRequest: RequestHandler = () => Observable.of()) {
constructor(handleRequest: RequestHandler = () => null) {
super();

@@ -17,5 +17,5 @@ this.request = handleRequest;

forward?: NextLink,
): Observable<FetchResult> {
): Observable<FetchResult> | null {
throw Error('should be overridden');
}
}

@@ -34,9 +34,2 @@ import * as Observable from 'zen-observable';

forward?: NextLink,
) => Observable<FetchResult>;
export type DevToolsMessage = {
network: {
operation: Operation;
result: FetchResult;
};
};
) => Observable<FetchResult> | null;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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