apollo-link-core
Advanced tools
Comparing version 0.1.1 to 0.2.0
import { execute, ApolloLink } from './link'; | ||
export { makePromise } from './linkUtils'; | ||
export * from './types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export default ApolloLink; | ||
export { Observable, ApolloLink, execute }; |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.makePromise = linkUtils_1.makePromise; | ||
var Observable = require("zen-observable-exported"); | ||
exports.Observable = Observable; | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
exports.Observable = zen_observable_ts_1.default; | ||
exports.default = link_1.ApolloLink; | ||
//# sourceMappingURL=index.js.map |
import { GraphQLRequest, NextLink, Operation, RequestHandler, FetchResult } from './types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export declare abstract class ApolloLink { | ||
@@ -4,0 +4,0 @@ static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; |
@@ -23,3 +23,3 @@ "use strict"; | ||
var graphql_tag_1 = require("graphql-tag"); | ||
var Observable = require("zen-observable-exported"); | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
var ApolloLink = (function () { | ||
@@ -35,6 +35,6 @@ function ApolloLink() { | ||
ApolloLink.empty = function () { | ||
return new FunctionLink(function (op, forward) { return Observable.of(); }); | ||
return new FunctionLink(function (op, forward) { return zen_observable_ts_1.default.of(); }); | ||
}; | ||
ApolloLink.passthrough = function () { | ||
return new FunctionLink(function (op, forward) { return (forward ? forward(op) : Observable.of()); }); | ||
return new FunctionLink(function (op, forward) { return (forward ? forward(op) : zen_observable_ts_1.default.of()); }); | ||
}; | ||
@@ -48,4 +48,4 @@ ApolloLink.split = function (test, left, right) { | ||
return test(operation) | ||
? leftLink.request(operation) || Observable.of() | ||
: rightLink.request(operation) || Observable.of(); | ||
? leftLink.request(operation) || zen_observable_ts_1.default.of() | ||
: rightLink.request(operation) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -56,4 +56,4 @@ } | ||
return test(operation) | ||
? leftLink.request(operation, forward) || Observable.of() | ||
: rightLink.request(operation, forward) || Observable.of(); | ||
? leftLink.request(operation, forward) || zen_observable_ts_1.default.of() | ||
: rightLink.request(operation, forward) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -76,3 +76,3 @@ } | ||
return new FunctionLink(function (operation) { | ||
return _this.request(operation, function (op) { return nextLink.request(op) || Observable.of(); }) || Observable.of(); | ||
return _this.request(operation, function (op) { return nextLink.request(op) || zen_observable_ts_1.default.of(); }) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -83,4 +83,4 @@ } | ||
return (_this.request(operation, function (op) { | ||
return nextLink.request(op, forward) || Observable.of(); | ||
}) || Observable.of()); | ||
return nextLink.request(op, forward) || zen_observable_ts_1.default.of(); | ||
}) || zen_observable_ts_1.default.of()); | ||
}); | ||
@@ -105,3 +105,3 @@ } | ||
} | ||
return link.request(transformOperation(copy)) || Observable.of(); | ||
return link.request(transformOperation(copy)) || zen_observable_ts_1.default.of(); | ||
} | ||
@@ -108,0 +108,0 @@ exports.execute = execute; |
import { GraphQLRequest, RequestHandler } from './types'; | ||
import { ApolloLink } from './link'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export declare function validateLink(link: ApolloLink): ApolloLink; | ||
@@ -5,0 +5,0 @@ export declare function validateOperation(operation: GraphQLRequest): GraphQLRequest; |
import { Operation, RequestHandler, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ApolloLink } from '../link'; | ||
@@ -4,0 +4,0 @@ export default class MockLink extends ApolloLink { |
import { Operation, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ApolloLink } from '../link'; | ||
@@ -4,0 +4,0 @@ export default class SetContextLink extends ApolloLink { |
@@ -1,4 +0,7 @@ | ||
export declare function checkCalls(calls: any, results: any): void; | ||
/// <reference types="sinon" /> | ||
import * as sinon from 'sinon'; | ||
import * as Links from '../link'; | ||
export declare function checkCalls<T>(calls: Array<sinon.SinonSpyCall>, results: Array<T>): void; | ||
export interface TestResultType { | ||
link: any; | ||
link: Links.ApolloLink; | ||
results?: any[]; | ||
@@ -5,0 +8,0 @@ query?: string; |
@@ -1,2 +0,2 @@ | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ExecutionResult, DocumentNode } from 'graphql'; | ||
@@ -3,0 +3,0 @@ export interface GraphQLRequest { |
@@ -14,3 +14,3 @@ "use strict"; | ||
var link_1 = require("../src/link"); | ||
var Observable = require("zen-observable-exported"); | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
var test_utils_1 = require("../src/test-utils"); | ||
@@ -26,3 +26,3 @@ var graphql_tag_1 = require("graphql-tag"); | ||
var link = returnOne.concat(function (operation, forward) { | ||
return Observable.of({ data: { count: operation.context.add } }); | ||
return zen_observable_ts_1.default.of({ data: { count: operation.context.add } }); | ||
}); | ||
@@ -37,3 +37,3 @@ test_utils_2.testLinkResults({ | ||
var returnOne = new test_utils_1.SetContextLink(setContext); | ||
var mock = new test_utils_1.MockLink(function (op) { return Observable.of({ data: op.context.add }); }); | ||
var mock = new test_utils_1.MockLink(function (op) { return zen_observable_ts_1.default.of({ data: op.context.add }); }); | ||
var link = returnOne.concat(mock); | ||
@@ -46,2 +46,16 @@ test_utils_2.testLinkResults({ | ||
}); | ||
it('should pass error to observable\'s error', function (done) { | ||
var error = new Error('thrown'); | ||
var returnOne = new test_utils_1.SetContextLink(setContext); | ||
var mock = new test_utils_1.MockLink(function (op) { return new zen_observable_ts_1.default(function (observer) { | ||
observer.next({ data: op.context.add }); | ||
observer.error(error); | ||
}); }); | ||
var link = returnOne.concat(mock); | ||
test_utils_2.testLinkResults({ | ||
link: link, | ||
results: [1, error], | ||
done: done, | ||
}); | ||
}); | ||
it('should concat a Link and function', function (done) { | ||
@@ -56,3 +70,3 @@ var returnOne = new test_utils_1.SetContextLink(setContext); | ||
var link = returnOne.concat(mock).concat(function (op) { | ||
return Observable.of({ data: op.context.add }); | ||
return zen_observable_ts_1.default.of({ data: op.context.add }); | ||
}); | ||
@@ -68,3 +82,3 @@ test_utils_2.testLinkResults({ | ||
var mock = new test_utils_1.MockLink(function (op, forward) { | ||
return Observable.of({ data: op.context.add }); | ||
return zen_observable_ts_1.default.of({ data: op.context.add }); | ||
}); | ||
@@ -94,3 +108,3 @@ var link = returnOne | ||
}) | ||
.concat(function (op, forward) { return Observable.of({ data: op.context.add }); }); | ||
.concat(function (op, forward) { return zen_observable_ts_1.default.of({ data: op.context.add }); }); | ||
test_utils_2.testLinkResults({ | ||
@@ -111,3 +125,3 @@ link: link, | ||
var mock2 = new test_utils_1.MockLink(function (op, forward) { | ||
return Observable.of({ data: op.context.add }); | ||
return zen_observable_ts_1.default.of({ data: op.context.add }); | ||
}); | ||
@@ -130,6 +144,6 @@ var link = returnOne.concat(mock1).concat(mock2); | ||
var mock2 = new test_utils_1.MockLink(function (op, forward) { | ||
return Observable.of({ data: op.context.add + 2 }); | ||
return zen_observable_ts_1.default.of({ data: op.context.add + 2 }); | ||
}); | ||
var mock3 = new test_utils_1.MockLink(function (op, forward) { | ||
return Observable.of({ data: op.context.add + 3 }); | ||
return zen_observable_ts_1.default.of({ data: op.context.add + 3 }); | ||
}); | ||
@@ -153,6 +167,6 @@ var link = returnOne.concat(mock1); | ||
var link1 = returnOne.concat(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 1 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 1 }); | ||
}); | ||
var link2 = returnOne.concat(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 2 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 2 }); | ||
}); | ||
@@ -175,6 +189,6 @@ var link = returnOne.split(function (operation) { return operation.context.add === 1; }, link1, link2); | ||
var link1 = returnOne.concat(new test_utils_1.MockLink(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 1 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 1 }); | ||
})); | ||
var link2 = returnOne.concat(new test_utils_1.MockLink(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 2 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 2 }); | ||
})); | ||
@@ -197,6 +211,6 @@ var link = returnOne.split(function (operation) { return operation.context.add === 1; }, link1, link2); | ||
var link1 = returnOne.concat(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 1 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 1 }); | ||
}); | ||
var link2 = returnOne.concat(new test_utils_1.MockLink(function (operation, forward) { | ||
return Observable.of({ data: operation.context.add + 2 }); | ||
return zen_observable_ts_1.default.of({ data: operation.context.add + 2 }); | ||
})); | ||
@@ -226,3 +240,3 @@ var link = returnOne.split(function (operation) { return operation.context.add === 1; }, link1, link2); | ||
}) | ||
.concat(function (operation) { return Observable.of({ data: operation.context.add }); }); | ||
.concat(function (operation) { return zen_observable_ts_1.default.of({ data: operation.context.add }); }); | ||
test_utils_2.testLinkResults({ | ||
@@ -245,3 +259,3 @@ link: link, | ||
var link = start.split(function (operation) { return operation.context.test; }, function (operation) { | ||
return Observable.of({ | ||
return zen_observable_ts_1.default.of({ | ||
data: { | ||
@@ -253,3 +267,3 @@ count: 1, | ||
var concat = link.concat(function (operation) { | ||
return Observable.of({ | ||
return zen_observable_ts_1.default.of({ | ||
data: { | ||
@@ -315,3 +329,3 @@ count: 2, | ||
}; | ||
var chain = link_1.ApolloLink.from([new test_utils_1.MockLink(function () { return Observable.of(data); })]); | ||
var chain = link_1.ApolloLink.from([new test_utils_1.MockLink(function () { return zen_observable_ts_1.default.of(data); })]); | ||
var observable = link_1.execute(chain, uniqueOperation); | ||
@@ -375,3 +389,3 @@ observable.subscribe({ | ||
}), | ||
new test_utils_1.MockLink(function () { return Observable.of(data); }), | ||
new test_utils_1.MockLink(function () { return zen_observable_ts_1.default.of(data); }), | ||
]); | ||
@@ -389,3 +403,3 @@ link_1.execute(chain, uniqueOperation); | ||
var observable = forward(op); | ||
return new Observable(function (observer) { | ||
return new zen_observable_ts_1.default(function (observer) { | ||
observable.subscribe({ | ||
@@ -403,3 +417,3 @@ next: function (actualData) { | ||
}), | ||
new test_utils_1.MockLink(function () { return Observable.of(data); }), | ||
new test_utils_1.MockLink(function () { return zen_observable_ts_1.default.of(data); }), | ||
]); | ||
@@ -432,3 +446,3 @@ var result = link_1.execute(chain, uniqueOperation); | ||
add1Link, | ||
function (operation) { return Observable.of({ data: operation.context }); }, | ||
function (operation) { return zen_observable_ts_1.default.of({ data: operation.context }); }, | ||
]); | ||
@@ -445,3 +459,3 @@ test_utils_2.testLinkResults({ | ||
it('should create filter when single link passed in', function (done) { | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return Observable.of({ data: { count: 1 } }); }); | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }); | ||
var context = { test: true }; | ||
@@ -462,3 +476,3 @@ test_utils_2.testLinkResults({ | ||
it('should split two functions', function (done) { | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return Observable.of({ data: { count: 1 } }); }, function (operation, forward) { return Observable.of({ data: { count: 2 } }); }); | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }, function (operation, forward) { return zen_observable_ts_1.default.of({ data: { count: 2 } }); }); | ||
var context = { test: true }; | ||
@@ -479,4 +493,4 @@ test_utils_2.testLinkResults({ | ||
it('should split two Links', function (done) { | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return Observable.of({ data: { count: 1 } }); }, new test_utils_1.MockLink(function (operation, forward) { | ||
return Observable.of({ data: { count: 2 } }); | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }, new test_utils_1.MockLink(function (operation, forward) { | ||
return zen_observable_ts_1.default.of({ data: { count: 2 } }); | ||
})); | ||
@@ -498,4 +512,4 @@ var context = { test: true }; | ||
it('should split a link and a function', function (done) { | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return Observable.of({ data: { count: 1 } }); }, new test_utils_1.MockLink(function (operation, forward) { | ||
return Observable.of({ data: { count: 2 } }); | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation, forward) { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }, new test_utils_1.MockLink(function (operation, forward) { | ||
return zen_observable_ts_1.default.of({ data: { count: 2 } }); | ||
})); | ||
@@ -522,3 +536,3 @@ var context = { test: true }; | ||
}); }); | ||
}).concat(function () { return Observable.of({ data: { count: 1 } }); }); | ||
}).concat(function () { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }); | ||
test_utils_2.testLinkResults({ | ||
@@ -539,3 +553,3 @@ link: link, | ||
var context = { test: true }; | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation) { return Observable.of({ data: { count: 2 } }); }).concat(function (operation) { return Observable.of({ data: { count: 1 } }); }); | ||
var link = link_1.ApolloLink.split(function (operation) { return operation.context.test; }, function (operation) { return zen_observable_ts_1.default.of({ data: { count: 2 } }); }).concat(function (operation) { return zen_observable_ts_1.default.of({ data: { count: 1 } }); }); | ||
test_utils_2.testLinkResults({ | ||
@@ -592,3 +606,3 @@ link: link, | ||
var context = { test: true }; | ||
var link = new test_utils_1.SetContextLink(function () { return context; }).split(function (op) { return op.context.test; }, function () { return Observable.of(); }, function () { return null; }); | ||
var link = new test_utils_1.SetContextLink(function () { return context; }).split(function (op) { return op.context.test; }, function () { return zen_observable_ts_1.default.of(); }, function () { return null; }); | ||
test_utils_2.testLinkResults({ | ||
@@ -617,3 +631,3 @@ link: link, | ||
chai_1.assert.property(op, 'context'); | ||
return Observable.of(); | ||
return zen_observable_ts_1.default.of(); | ||
}, | ||
@@ -647,3 +661,3 @@ ]); | ||
it('should warn if attempting to concat to a terminating Link from function', function () { | ||
var link = link_1.ApolloLink.from([function (operation) { return Observable.of({ data: data }); }]); | ||
var link = link_1.ApolloLink.from([function (operation) { return zen_observable_ts_1.default.of({ data: data }); }]); | ||
chai_1.assert.deepEqual(link.concat(function (operation, forward) { return forward(operation); }), link); | ||
@@ -654,3 +668,3 @@ chai_1.assert(warningStub.calledOnce); | ||
it('should warn if attempting to concat to a terminating Link', function () { | ||
var link = new test_utils_1.MockLink(function (operation) { return Observable.of(); }); | ||
var link = new test_utils_1.MockLink(function (operation) { return zen_observable_ts_1.default.of(); }); | ||
chai_1.assert.deepEqual(link.concat(function (operation, forward) { return forward(operation); }), link); | ||
@@ -662,3 +676,3 @@ chai_1.assert(warningStub.calledOnce); | ||
var link = new test_utils_1.MockLink(function (operation, forward) { return forward(operation); }); | ||
link.concat(function (operation) { return Observable.of(); }); | ||
link.concat(function (operation) { return zen_observable_ts_1.default.of(); }); | ||
chai_1.assert(warningStub.notCalled); | ||
@@ -669,3 +683,3 @@ }); | ||
it('should not warn if attempting to split a terminating and non-terminating Link', function () { | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return Observable.of({ data: data }); }, function (operation, forward) { return forward(operation); }); | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, function (operation, forward) { return forward(operation); }); | ||
split.concat(function (operation, forward) { return forward(operation); }); | ||
@@ -675,3 +689,3 @@ chai_1.assert(warningStub.notCalled); | ||
it('should warn if attempting to concat to split two terminating links', function () { | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return Observable.of({ data: data }); }, function (operation) { return Observable.of({ data: data }); }); | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, function (operation) { return zen_observable_ts_1.default.of({ data: data }); }); | ||
chai_1.assert.deepEqual(split.concat(function (operation, forward) { return forward(operation); }), split); | ||
@@ -681,3 +695,3 @@ chai_1.assert(warningStub.calledOnce); | ||
it('should warn if attempting to split to split two terminating links', function () { | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return Observable.of({ data: data }); }, function (operation) { return Observable.of({ data: data }); }); | ||
var split = link_1.ApolloLink.split(function () { return true; }, function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, function (operation) { return zen_observable_ts_1.default.of({ data: data }); }); | ||
chai_1.assert.deepEqual(split.split(function () { return true; }, function (operation, forward) { return forward(operation); }, function (operation, forward) { return forward(operation); }), split); | ||
@@ -691,3 +705,3 @@ chai_1.assert(warningStub.calledOnce); | ||
function (operation, forward) { return forward(operation); }, | ||
function (operation) { return Observable.of({ data: data }); }, | ||
function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, | ||
]); | ||
@@ -699,3 +713,3 @@ chai_1.assert(warningStub.notCalled); | ||
function (operation, forward) { return forward(operation); }, | ||
function (operation) { return Observable.of({ data: data }); }, | ||
function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, | ||
function (operation, forward) { return forward(operation); }, | ||
@@ -708,3 +722,3 @@ ]); | ||
function (operation, forward) { return forward(operation); }, | ||
function (operation) { return Observable.of({ data: data }); }, | ||
function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, | ||
function (operation, forward) { return forward(operation); }, | ||
@@ -718,3 +732,3 @@ ]); | ||
var terminatingLink = new test_utils_1.MockLink(function (operation) { | ||
return Observable.of({ data: data }); | ||
return zen_observable_ts_1.default.of({ data: data }); | ||
}); | ||
@@ -727,3 +741,3 @@ link_1.ApolloLink.from([ | ||
function (operation, forward) { return forward(operation); }, | ||
function (operation) { return Observable.of({ data: data }); }, | ||
function (operation) { return zen_observable_ts_1.default.of({ data: data }); }, | ||
function (operation, forward) { return forward(operation); }, | ||
@@ -730,0 +744,0 @@ ]); |
@@ -6,3 +6,3 @@ "use strict"; | ||
var LinkUtils = require("../src/linkUtils"); | ||
var Observable = require("zen-observable-exported"); | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
describe('Link utilities:', function () { | ||
@@ -35,3 +35,3 @@ describe('validateOperation', function () { | ||
it('return next call as Promise resolution', function () { | ||
return LinkUtils.makePromise(Observable.of(data)).then(function (result) { | ||
return LinkUtils.makePromise(zen_observable_ts_1.default.of(data)).then(function (result) { | ||
return chai_1.assert.deepEqual(data, result); | ||
@@ -41,3 +41,3 @@ }); | ||
it('return error call as Promise rejection', function () { | ||
return LinkUtils.makePromise(new Observable(function (observer) { return observer.error(error); })) | ||
return LinkUtils.makePromise(new zen_observable_ts_1.default(function (observer) { return observer.error(error); })) | ||
.then(chai_1.expect.fail) | ||
@@ -58,3 +58,3 @@ .catch(function (actualError) { return chai_1.assert.deepEqual(error, actualError); }); | ||
spy.callsFake(function () { return done(); }); | ||
LinkUtils.makePromise(Observable.of(data, data)).then(function (result) { | ||
LinkUtils.makePromise(zen_observable_ts_1.default.of(data, data)).then(function (result) { | ||
return chai_1.assert.deepEqual(data, result); | ||
@@ -61,0 +61,0 @@ }); |
import { execute, ApolloLink } from './link'; | ||
export { makePromise } from './linkUtils'; | ||
export * from './types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export default ApolloLink; | ||
export { Observable, ApolloLink, execute }; |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.makePromise = linkUtils_1.makePromise; | ||
var Observable = require("zen-observable-exported"); | ||
exports.Observable = Observable; | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
exports.Observable = zen_observable_ts_1.default; | ||
exports.default = link_1.ApolloLink; | ||
//# sourceMappingURL=index.js.map |
import { GraphQLRequest, NextLink, Operation, RequestHandler, FetchResult } from './types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export declare abstract class ApolloLink { | ||
@@ -4,0 +4,0 @@ static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; |
@@ -23,3 +23,3 @@ "use strict"; | ||
var graphql_tag_1 = require("graphql-tag"); | ||
var Observable = require("zen-observable-exported"); | ||
var zen_observable_ts_1 = require("zen-observable-ts"); | ||
var ApolloLink = (function () { | ||
@@ -35,6 +35,6 @@ function ApolloLink() { | ||
ApolloLink.empty = function () { | ||
return new FunctionLink(function (op, forward) { return Observable.of(); }); | ||
return new FunctionLink(function (op, forward) { return zen_observable_ts_1.default.of(); }); | ||
}; | ||
ApolloLink.passthrough = function () { | ||
return new FunctionLink(function (op, forward) { return (forward ? forward(op) : Observable.of()); }); | ||
return new FunctionLink(function (op, forward) { return (forward ? forward(op) : zen_observable_ts_1.default.of()); }); | ||
}; | ||
@@ -48,4 +48,4 @@ ApolloLink.split = function (test, left, right) { | ||
return test(operation) | ||
? leftLink.request(operation) || Observable.of() | ||
: rightLink.request(operation) || Observable.of(); | ||
? leftLink.request(operation) || zen_observable_ts_1.default.of() | ||
: rightLink.request(operation) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -56,4 +56,4 @@ } | ||
return test(operation) | ||
? leftLink.request(operation, forward) || Observable.of() | ||
: rightLink.request(operation, forward) || Observable.of(); | ||
? leftLink.request(operation, forward) || zen_observable_ts_1.default.of() | ||
: rightLink.request(operation, forward) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -76,3 +76,3 @@ } | ||
return new FunctionLink(function (operation) { | ||
return _this.request(operation, function (op) { return nextLink.request(op) || Observable.of(); }) || Observable.of(); | ||
return _this.request(operation, function (op) { return nextLink.request(op) || zen_observable_ts_1.default.of(); }) || zen_observable_ts_1.default.of(); | ||
}); | ||
@@ -83,4 +83,4 @@ } | ||
return (_this.request(operation, function (op) { | ||
return nextLink.request(op, forward) || Observable.of(); | ||
}) || Observable.of()); | ||
return nextLink.request(op, forward) || zen_observable_ts_1.default.of(); | ||
}) || zen_observable_ts_1.default.of()); | ||
}); | ||
@@ -105,3 +105,3 @@ } | ||
} | ||
return link.request(transformOperation(copy)) || Observable.of(); | ||
return link.request(transformOperation(copy)) || zen_observable_ts_1.default.of(); | ||
} | ||
@@ -108,0 +108,0 @@ exports.execute = execute; |
import { GraphQLRequest, RequestHandler } from './types'; | ||
import { ApolloLink } from './link'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export declare function validateLink(link: ApolloLink): ApolloLink; | ||
@@ -5,0 +5,0 @@ export declare function validateOperation(operation: GraphQLRequest): GraphQLRequest; |
import { Operation, RequestHandler, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ApolloLink } from '../link'; | ||
@@ -4,0 +4,0 @@ export default class MockLink extends ApolloLink { |
import { Operation, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ApolloLink } from '../link'; | ||
@@ -4,0 +4,0 @@ export default class SetContextLink extends ApolloLink { |
@@ -1,4 +0,7 @@ | ||
export declare function checkCalls(calls: any, results: any): void; | ||
/// <reference types="sinon" /> | ||
import * as sinon from 'sinon'; | ||
import * as Links from '../link'; | ||
export declare function checkCalls<T>(calls: Array<sinon.SinonSpyCall>, results: Array<T>): void; | ||
export interface TestResultType { | ||
link: any; | ||
link: Links.ApolloLink; | ||
results?: any[]; | ||
@@ -5,0 +8,0 @@ query?: string; |
@@ -1,2 +0,2 @@ | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ExecutionResult, DocumentNode } from 'graphql'; | ||
@@ -3,0 +3,0 @@ export interface GraphQLRequest { |
{ | ||
"name": "apollo-link-core", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Flexible, lightweight transport layer for GraphQL", | ||
@@ -29,3 +29,3 @@ "author": "Evans Hauser <evanshauser@gmail.com>", | ||
"test-watch": "mocha --reporter spec --full-trace dist/tests/tests.js --watch", | ||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace dist/tests/tests.js", | ||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter dot --full-trace dist/tests/tests.js", | ||
"postcoverage": "remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info", | ||
@@ -45,3 +45,3 @@ "lint": "tslint --type-check -p tsconfig.json src/*.ts && tslint --type-check -p tsconfig.json tests/*.ts", | ||
"graphql-tag": "^2.4.2", | ||
"zen-observable-exported": "^0.5.2" | ||
"zen-observable-ts": "^0.1.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "devDependencies": { |
@@ -5,5 +5,5 @@ import { execute, ApolloLink } from './link'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
export default ApolloLink; | ||
export { Observable, ApolloLink, execute }; |
@@ -19,3 +19,3 @@ import { | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { | ||
@@ -22,0 +22,0 @@ DocumentNode, |
@@ -5,3 +5,3 @@ import { GraphQLRequest, RequestHandler } from './types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
@@ -8,0 +8,0 @@ export function validateLink(link: ApolloLink): ApolloLink { |
import { Operation, RequestHandler, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
@@ -5,0 +5,0 @@ import { ApolloLink } from '../link'; |
import { Operation, NextLink, FetchResult } from '../types'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
@@ -5,0 +5,0 @@ import { ApolloLink } from '../link'; |
@@ -13,3 +13,6 @@ import { assert } from 'chai'; | ||
export function checkCalls(calls, results) { | ||
export function checkCalls<T>( | ||
calls: Array<sinon.SinonSpyCall>, | ||
results: Array<T>, | ||
) { | ||
assert.deepEqual(calls.length, results.length); | ||
@@ -20,3 +23,3 @@ calls.map((call, i) => assert.deepEqual(call.args[0].data, results[i])); | ||
export interface TestResultType { | ||
link; | ||
link: Links.ApolloLink; | ||
results?: any[]; | ||
@@ -23,0 +26,0 @@ query?: string; |
@@ -1,2 +0,2 @@ | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { ExecutionResult, DocumentNode } from 'graphql'; | ||
@@ -3,0 +3,0 @@ |
import { assert, expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import { execute, ApolloLink } from '../src/link'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
import { MockLink, SetContextLink } from '../src/test-utils'; | ||
import gql from 'graphql-tag'; | ||
import { FetchResult, Operation } from '../src/types'; | ||
import { FetchResult, Operation, NextLink } from '../src/types'; | ||
@@ -46,2 +46,21 @@ import { testLinkResults } from '../src/test-utils'; | ||
it("should pass error to observable's error", done => { | ||
const error = new Error('thrown'); | ||
const returnOne = new SetContextLink(setContext); | ||
const mock = new MockLink( | ||
op => | ||
new Observable(observer => { | ||
observer.next({ data: op.context.add }); | ||
observer.error(error); | ||
}), | ||
); | ||
const link = returnOne.concat(mock); | ||
testLinkResults({ | ||
link, | ||
results: [1, error], | ||
done, | ||
}); | ||
}); | ||
it('should concat a Link and function', done => { | ||
@@ -527,3 +546,3 @@ const returnOne = new SetContextLink(setContext); | ||
it('should chain together a function with links', done => { | ||
const add1 = (operation, forward) => { | ||
const add1 = (operation: Operation, forward: NextLink) => { | ||
operation.context.num++; | ||
@@ -709,3 +728,3 @@ return forward(operation); | ||
describe('execute', () => { | ||
let _warn; | ||
let _warn: (message?: any, ...originalParams: any[]) => void; | ||
@@ -712,0 +731,0 @@ before(() => { |
import { assert, expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import * as LinkUtils from '../src/linkUtils'; | ||
import * as Observable from 'zen-observable-exported'; | ||
import Observable from 'zen-observable-ts'; | ||
@@ -53,3 +53,3 @@ describe('Link utilities:', () => { | ||
const spy = sinon.stub(); | ||
let _warn; | ||
let _warn: (message?: any, ...originalParams: any[]) => void; | ||
@@ -56,0 +56,0 @@ before(() => { |
@@ -12,3 +12,3 @@ { | ||
"outDir": "dist", | ||
"noImplicitAny": false, | ||
"noImplicitAny": true, | ||
"noUnusedParameters": false, | ||
@@ -15,0 +15,0 @@ "noUnusedLocals": true, |
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
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
296548
87
3402
+ Addedzen-observable-ts@^0.1.0
+ Addedzen-observable-ts@0.1.0(transitive)
- Removedzen-observable-exported@^0.5.2