slicknode-apollo-link
Advanced tools
Comparing version 1.0.4 to 2.0.1
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const apollo_link_1 = require("apollo-link"); | ||
const core_1 = require("@apollo/client/core"); | ||
const chai_1 = require("chai"); | ||
const graphql_tag_1 = __importDefault(require("graphql-tag")); | ||
const sinon_1 = __importDefault(require("sinon")); | ||
@@ -25,11 +36,11 @@ const SlicknodeLink_1 = __importStar(require("../SlicknodeLink")); | ||
const nextLink = sinon_1.default.stub().callsFake((e) => { | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
}); | ||
}); | ||
const slicknodeLink = apollo_link_1.ApolloLink.from([ | ||
const slicknodeLink = core_1.ApolloLink.from([ | ||
new SlicknodeLink_1.default(), | ||
new apollo_link_1.ApolloLink(nextLink), | ||
new core_1.ApolloLink(nextLink), | ||
]); | ||
const query = graphql_tag_1.default `{test}`; | ||
const query = core_1.gql `{test}`; | ||
const request = { | ||
@@ -39,3 +50,3 @@ query, | ||
}; | ||
const observable = apollo_link_1.execute(slicknodeLink, request); | ||
const observable = core_1.execute(slicknodeLink, request); | ||
observable.subscribe({ | ||
@@ -58,5 +69,5 @@ next(result) { | ||
}); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
chai_1.expect(operation.getContext()).to.deep.equal({ | ||
@@ -71,3 +82,3 @@ headers: { | ||
]); | ||
const query = graphql_tag_1.default `{test}`; | ||
const query = core_1.gql `{test}`; | ||
const request = { | ||
@@ -77,3 +88,3 @@ query, | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -98,5 +109,5 @@ next(result) { | ||
slicknodeLink.setAuthTokenSet(authTokenSet); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
chai_1.expect(operation.getContext()).to.deep.equal({ | ||
@@ -111,3 +122,3 @@ headers: { | ||
]); | ||
const query = graphql_tag_1.default `{test}`; | ||
const query = core_1.gql `{test}`; | ||
const request = { | ||
@@ -117,3 +128,3 @@ query, | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -175,5 +186,5 @@ next(result) { | ||
slicknodeLink.setAuthTokenSet(authTokenSet); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
chai_1.expect(operation.getContext()).to.deep.equal({ | ||
@@ -186,3 +197,3 @@ headers: {}, | ||
]); | ||
const query = graphql_tag_1.default `{test}`; | ||
const query = core_1.gql `{test}`; | ||
const request = { | ||
@@ -192,3 +203,3 @@ query, | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -220,9 +231,9 @@ next(result) { | ||
let refreshTokenExecuted = false; | ||
const query = graphql_tag_1.default `{test}`; | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const query = core_1.gql `{test}`; | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
if (!refreshTokenExecuted) { | ||
// First request refreshes auth tokens | ||
chai_1.expect(operation.query).to.deep.equal(graphql_tag_1.default `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.query).to.deep.equal(core_1.gql `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.variables).to.deep.equal({ | ||
@@ -233,3 +244,3 @@ token: authTokenSet.refreshToken, | ||
refreshTokenExecuted = true; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ | ||
@@ -250,3 +261,3 @@ data: { | ||
}); | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -260,3 +271,3 @@ }); | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -289,9 +300,9 @@ next(result) { | ||
let refreshTokenExecuted = false; | ||
const query = graphql_tag_1.default `{test}`; | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const query = core_1.gql `{test}`; | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
if (!refreshTokenExecuted) { | ||
// First request refreshes auth tokens | ||
chai_1.expect(operation.query).to.deep.equal(graphql_tag_1.default `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.query).to.deep.equal(core_1.gql `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.variables).to.deep.equal({ | ||
@@ -302,3 +313,3 @@ token: authTokenSet.refreshToken, | ||
refreshTokenExecuted = true; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
// Run in next event loop to test concurrent requests | ||
@@ -322,3 +333,3 @@ setTimeout(() => { | ||
}); | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -333,4 +344,4 @@ }); | ||
// Execute two requests concurrently | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable2 = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
const observable2 = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -370,9 +381,9 @@ next(result) { | ||
let refreshTokenExecuted = false; | ||
const query = graphql_tag_1.default `{test}`; | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const query = core_1.gql `{test}`; | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
if (!refreshTokenExecuted) { | ||
// First request refreshes auth tokens | ||
chai_1.expect(operation.query).to.deep.equal(graphql_tag_1.default `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.query).to.deep.equal(core_1.gql `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.variables).to.deep.equal({ | ||
@@ -383,3 +394,3 @@ token: authTokenSet.refreshToken, | ||
refreshTokenExecuted = true; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ | ||
@@ -397,3 +408,3 @@ data: { | ||
chai_1.expect(slicknodeLink.getRefreshToken()).to.be.null; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -407,3 +418,3 @@ }); | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -436,9 +447,9 @@ next(result) { | ||
let refreshTokenExecuted = false; | ||
const query = graphql_tag_1.default `{test}`; | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const query = core_1.gql `{test}`; | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink((operation) => { | ||
new core_1.ApolloLink((operation) => { | ||
if (!refreshTokenExecuted) { | ||
// First request refreshes auth tokens | ||
chai_1.expect(operation.query).to.deep.equal(graphql_tag_1.default `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.query).to.deep.equal(core_1.gql `${SlicknodeLink_1.REFRESH_TOKEN_MUTATION}`); | ||
chai_1.expect(operation.variables).to.deep.equal({ | ||
@@ -449,3 +460,3 @@ token: authTokenSet.refreshToken, | ||
refreshTokenExecuted = true; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ | ||
@@ -463,3 +474,3 @@ data: { | ||
chai_1.expect(slicknodeLink.hasAccessToken()).to.be.false; | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -473,3 +484,3 @@ }); | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -494,6 +505,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -503,3 +514,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation { | ||
const query = core_1.gql `mutation { | ||
loginMutation @authenticate { | ||
@@ -516,3 +527,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -543,6 +554,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -552,3 +563,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation LoginMutation { | ||
const query = core_1.gql `mutation LoginMutation { | ||
loginMutation @authenticate { | ||
@@ -567,3 +578,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -588,6 +599,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -597,3 +608,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation { | ||
const query = core_1.gql `mutation { | ||
loginMutation @authenticate { | ||
@@ -610,3 +621,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -629,6 +640,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -638,3 +649,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation { | ||
const query = core_1.gql `mutation { | ||
loginMutation @authenticate { | ||
@@ -651,3 +662,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -675,6 +686,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -684,3 +695,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation { | ||
const query = core_1.gql `mutation { | ||
loginMutation @authenticate { | ||
@@ -697,3 +708,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -722,6 +733,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -731,3 +742,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `query LoginMutation { | ||
const query = core_1.gql `query LoginMutation { | ||
loginMutation @authenticate { | ||
@@ -746,3 +757,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -771,6 +782,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -780,3 +791,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation LoginMutation { | ||
const query = core_1.gql `mutation LoginMutation { | ||
loginMutation { | ||
@@ -795,3 +806,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -822,3 +833,3 @@ next(result) { | ||
const nextLink = sinon_1.default.stub().callsFake(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
dataLoaderStub(); | ||
@@ -828,7 +839,7 @@ observer.next({ data }); | ||
}); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(nextLink), | ||
new core_1.ApolloLink(nextLink), | ||
]); | ||
const query = graphql_tag_1.default `mutation LoginMutation { | ||
const query = core_1.gql `mutation LoginMutation { | ||
alias: loginMutation @authenticate { | ||
@@ -847,3 +858,3 @@ accessToken | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -878,6 +889,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -887,3 +898,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation LoginMutation { | ||
const query = core_1.gql `mutation LoginMutation { | ||
otherMutation | ||
@@ -904,3 +915,3 @@ loginMutation @authenticate { | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -934,6 +945,6 @@ next(result) { | ||
slicknodeLink.setAuthTokenSet(authTokenSet); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
new apollo_link_1.ApolloLink(() => { | ||
return new apollo_link_1.Observable((observer) => { | ||
new core_1.ApolloLink(() => { | ||
return new core_1.Observable((observer) => { | ||
observer.next({ data }); | ||
@@ -943,3 +954,3 @@ }); | ||
]); | ||
const query = graphql_tag_1.default `mutation LogoutMutation($token: String) { | ||
const query = core_1.gql `mutation LogoutMutation($token: String) { | ||
logoutUser(input: {refreshToken: $token}) { | ||
@@ -955,3 +966,3 @@ success | ||
}; | ||
const observable = apollo_link_1.execute(link, request); | ||
const observable = core_1.execute(link, request); | ||
observable.subscribe({ | ||
@@ -971,6 +982,6 @@ next(result) { | ||
const slicknodeLink = new SlicknodeLink_1.default(); | ||
const link = apollo_link_1.ApolloLink.from([ | ||
const link = core_1.ApolloLink.from([ | ||
slicknodeLink, | ||
]); | ||
const query = graphql_tag_1.default `{test}`; | ||
const query = core_1.gql `{test}`; | ||
const request = { | ||
@@ -981,3 +992,3 @@ query, | ||
chai_1.expect(() => { | ||
apollo_link_1.execute(link, request); | ||
core_1.execute(link, request); | ||
}).to.throw('Network link is missing in apollo client or SlicknodeLink is last link in the chain.'); | ||
@@ -984,0 +995,0 @@ }); |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.REFRESH_TOKEN_MUTATION = exports.LOGOUT_MUTATION = exports.default = void 0; | ||
var SlicknodeLink_1 = require("./SlicknodeLink"); | ||
exports.default = SlicknodeLink_1.default; | ||
exports.LOGOUT_MUTATION = SlicknodeLink_1.LOGOUT_MUTATION; | ||
exports.REFRESH_TOKEN_MUTATION = SlicknodeLink_1.REFRESH_TOKEN_MUTATION; | ||
__export(require("./storage")); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(SlicknodeLink_1).default; } }); | ||
Object.defineProperty(exports, "LOGOUT_MUTATION", { enumerable: true, get: function () { return SlicknodeLink_1.LOGOUT_MUTATION; } }); | ||
Object.defineProperty(exports, "REFRESH_TOKEN_MUTATION", { enumerable: true, get: function () { return SlicknodeLink_1.REFRESH_TOKEN_MUTATION; } }); | ||
__exportStar(require("./storage"), exports); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,6 @@ | ||
import { ApolloLink, FetchResult, NextLink, Observable, Operation } from 'apollo-link'; | ||
/// <reference types="zen-observable" /> | ||
import { ApolloLink, FetchResult, NextLink, Observable, Operation } from '@apollo/client/core'; | ||
import { IAuthTokenSet, ISlicknodeLinkOptions, IStorage } from './types'; | ||
export declare const REFRESH_TOKEN_MUTATION: any; | ||
export declare const LOGOUT_MUTATION: any; | ||
export declare const REFRESH_TOKEN_MUTATION: import("graphql/language").DocumentNode; | ||
export declare const LOGOUT_MUTATION: import("graphql/language").DocumentNode; | ||
/** | ||
@@ -6,0 +7,0 @@ * SlicknodeLink instance to be used to load data with apollo-client |
@@ -15,5 +15,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const apollo_link_1 = require("apollo-link"); | ||
const apollo_utilities_1 = require("apollo-utilities"); | ||
const graphql_tag_1 = __importDefault(require("graphql-tag")); | ||
exports.LOGOUT_MUTATION = exports.REFRESH_TOKEN_MUTATION = void 0; | ||
const core_1 = require("@apollo/client/core"); | ||
const utils_1 = require("@apollo/client/link/utils"); | ||
const utilities_1 = require("@apollo/client/utilities"); | ||
const MemoryStorage_1 = __importDefault(require("./storage/MemoryStorage")); | ||
@@ -25,3 +26,3 @@ const REFRESH_TOKEN_KEY = ':auth:refreshToken'; | ||
const DEFAULT_NAMESPACE = 'slicknode'; | ||
exports.REFRESH_TOKEN_MUTATION = graphql_tag_1.default `mutation refreshToken($token: String!) { | ||
exports.REFRESH_TOKEN_MUTATION = core_1.gql `mutation refreshToken($token: String!) { | ||
refreshAuthToken(input: {refreshToken: $token}) { | ||
@@ -34,3 +35,3 @@ accessToken | ||
}`; | ||
exports.LOGOUT_MUTATION = graphql_tag_1.default `mutation logout($refreshToken: String) { | ||
exports.LOGOUT_MUTATION = core_1.gql `mutation logout($refreshToken: String) { | ||
logoutUser(input:{refreshToken:$refreshToken}) { | ||
@@ -48,3 +49,3 @@ success | ||
*/ | ||
class SlicknodeLink extends apollo_link_1.ApolloLink { | ||
class SlicknodeLink extends core_1.ApolloLink { | ||
/** | ||
@@ -70,3 +71,3 @@ * Constructor | ||
} | ||
return new apollo_link_1.Observable((observer) => { | ||
return new core_1.Observable((observer) => { | ||
this.getAuthHeaders(forward) | ||
@@ -126,3 +127,3 @@ .then((authHeaders) => { | ||
// Remove @authenticated directives from document | ||
operation.query = apollo_utilities_1.removeDirectivesFromDocument([authenticationDirectiveRemoveConfig], operation.query); | ||
operation.query = utilities_1.removeDirectivesFromDocument([authenticationDirectiveRemoveConfig], operation.query); | ||
const nextObservable = forward(operation); | ||
@@ -282,3 +283,3 @@ // Add result listeners for token and logout processing | ||
this.debug('No valid access token found, obtaining new AuthTokenSet with refresh token'); | ||
const refreshOperation = apollo_link_1.createOperation({}, { | ||
const refreshOperation = utils_1.createOperation({}, { | ||
query: exports.REFRESH_TOKEN_MUTATION, | ||
@@ -285,0 +286,0 @@ variables: { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MemoryStorage = void 0; | ||
var MemoryStorage_1 = require("./MemoryStorage"); | ||
exports.MemoryStorage = MemoryStorage_1.default; | ||
Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return __importDefault(MemoryStorage_1).default; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "slicknode-apollo-link", | ||
"version": "1.0.4", | ||
"version": "2.0.1", | ||
"repository": "https://github.com/slicknode/slicknode-apollo-link.git", | ||
@@ -31,16 +31,17 @@ "author": "Ivo Meißner <info@overtronic.com>", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.4", | ||
"@types/graphql": "^14.0.3", | ||
"@types/mocha": "^5.2.5", | ||
"@types/sinon": "^5.0.2", | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.2", | ||
"graphql": "^14.0.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.0.1", | ||
"rimraf": "^2.6.2", | ||
"sinon": "^6.3.1", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.3" | ||
"@apollo/client": "^3.3.21", | ||
"@types/chai": "^4.2.21", | ||
"@types/mocha": "^8.2.3", | ||
"@types/node": "^16.3.2", | ||
"@types/sinon": "^10.0.2", | ||
"chai": "^4.3.4", | ||
"coveralls": "^3.1.1", | ||
"graphql": "^15.5.1", | ||
"mocha": "^9.0.2", | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^11.1.1", | ||
"ts-node": "^10.1.0", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
@@ -63,10 +64,7 @@ "nyc": { | ||
}, | ||
"dependencies": { | ||
"apollo-link": "^1.2.2", | ||
"apollo-utilities": "^1.0.26", | ||
"graphql-tag": "^2.10.0" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" | ||
"@apollo/client": "^3.3.21", | ||
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" | ||
} | ||
} |
@@ -6,5 +6,7 @@ # Slicknode Apollo Link | ||
ApolloLink component that automatically sets authentication headers for GraphQL requests via the [apollo-client](https://www.apollographql.com/client). It stores the access and refresh tokens in a store (for example InMemory, localStorage, sessionStorage etc.) and keeps track of expiration times. | ||
ApolloLink component that automatically sets authentication headers for GraphQL requests via the [@apollo/client](https://www.apollographql.com/client). It stores the access and refresh tokens in a store (for example InMemory, localStorage, sessionStorage etc.) and keeps track of expiration times. | ||
If auth tokens expire, they are automatically refreshed in the background when a request is issued, without interruption to the user. Can be combined with any of the available [apollo links](https://www.apollographql.com/docs/link/#linkslist). | ||
Works with any GraphQL API that implements auth mutations as outlined in the [Slicknode documentation](https://slicknode.com/docs/auth/authentication/). | ||
## Installation | ||
@@ -14,5 +16,5 @@ | ||
yarn add slicknode-apollo-link | ||
npm install slicknode-apollo-link | ||
There is also a peer dependencie to `graphql` which you should already have installed when you are using the [apollo-client](https://www.apollographql.com/client). | ||
Slicknode Apollo Link has peer dependencies to `graphql` and `@apollo/client` which you should already have installed when you are using the [Apollo Client](https://www.apollographql.com/client). | ||
@@ -25,32 +27,40 @@ ## Usage | ||
```javascript | ||
import { | ||
ApolloClient, | ||
InMemoryCache, | ||
ApolloProvider, | ||
HttpLink, | ||
ApolloLink, | ||
} from '@apollo/client'; | ||
import SlicknodeLink from 'slicknode-apollo-link'; | ||
import { ApolloClient } from 'apollo-client'; | ||
import { InMemoryCache } from 'apollo-cache-inmemory'; | ||
import { ApolloLink } from 'apollo-link'; | ||
import { HttpLink } from 'apollo-link-http'; | ||
const slicknodeLink = new SlicknodeLink({ | ||
debug: true // Write debug info to console, disable in production | ||
debug: true, // Writes auth debug info to console, disable in production | ||
}); | ||
// Create the ApolloClient instance to use in your projects | ||
const SLICKNODE_ENDPOINT = | ||
'https://api.us-east-1.aws.slicknode.com/v1/your-project'; | ||
const client = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
// Create link chain | ||
link: ApolloLink.from([ | ||
// Add the slicknode link somewhere before the HttpLink | ||
// Add Slicknode link before HttpLink to add auth headers | ||
slicknodeLink, | ||
// ... more links (retry, error handling etc.) | ||
// ...More links for error handling etc... | ||
// Network link to make HTTP requests to the API | ||
new HttpLink({ | ||
// Add your slicknode GraphQL endpoint here | ||
uri: 'https://you-project.slicknode.com', | ||
uri: SLICKNODE_ENDPOINT, | ||
credentials: 'same-origin', | ||
headers: { | ||
// Uncomment to enable preview mode: | ||
// 'X-Slicknode-Preview': '1', | ||
// Uncomment to set default locale: | ||
// 'X-Slicknode-Locale': 'en-US', | ||
}, | ||
}), | ||
]), | ||
// Add a cache (required by apollo, change as needed...) | ||
cache: new InMemoryCache() | ||
}); | ||
// Use the client as usual... (See apollo-client documentation) | ||
``` | ||
@@ -66,3 +76,3 @@ | ||
Make sure that the module with the login mutation is installed and deployed to your Slicknode server. See the list of | ||
[available auth modules](#available-auth-modules) for details. | ||
[available auth modules](https://slicknode.com/docs/auth/authentication/#authentication-modules) for details. | ||
@@ -72,3 +82,3 @@ For example: | ||
```javascript | ||
import { gql } from 'graphql-tag'; | ||
import { gql } from '@apollo/client'; | ||
@@ -122,4 +132,2 @@ client.query(gql` | ||
### Available Auth Modules | ||
You might want to clear the apollo client cache after logging a user out to not accidentally expose private data. |
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
101162
2
1481
128
15
+ Added@apollo/client@3.12.7(transitive)
+ Added@graphql-typed-document-node/core@3.2.0(transitive)
+ Added@wry/caches@1.0.1(transitive)
+ Added@wry/context@0.7.4(transitive)
+ Added@wry/equality@0.5.7(transitive)
+ Added@wry/trie@0.5.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedgraphql@15.10.1(transitive)
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedoptimism@0.18.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrehackt@0.1.0(transitive)
+ Addedresponse-iterator@0.2.19(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsymbol-observable@4.0.0(transitive)
+ Addedts-invariant@0.10.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedzen-observable-ts@1.2.5(transitive)
- Removedapollo-link@^1.2.2
- Removedapollo-utilities@^1.0.26
- Removedgraphql-tag@^2.10.0
- Removed@wry/equality@0.1.11(transitive)
- Removedapollo-link@1.2.14(transitive)
- Removedapollo-utilities@1.3.4(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedgraphql@14.7.0(transitive)
- Removediterall@1.3.0(transitive)
- Removedts-invariant@0.4.4(transitive)
- Removedtslib@1.14.1(transitive)
- Removedzen-observable-ts@0.8.21(transitive)