diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb9572f62b..728e2758409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 3 to 6 months), to signal the start of a more stable API. ### vNEXT +- Removed AuthTokenHeaderMiddleware code and related tests from apollo-client [Issue #247](https://github.com/apollostack/apollo-client/issues/247) - Fixed the getFromAST functions so that they work with queries that have named fragments (i.e. working toward named fragment support) - Added basic guards to our Redux Store `subscribe` to prevent `broadcastQueries` from being called unnecessarily diff --git a/src/middleware.ts b/src/middleware.ts index 940f4672a3a..ffff09c8e4b 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -8,29 +8,3 @@ export interface MiddlewareRequest { export interface MiddlewareInterface { applyMiddleware(request: MiddlewareRequest, next: Function); } - -export class AuthTokenHeaderMiddleware implements MiddlewareInterface { - private _token = null; - private _header = 'Authorization'; - - public setToken = (token: string) => { - this._token = token; - }; - - public setHeader = (header: string) => { - this._header = header; - }; - - public applyMiddleware = (request: MiddlewareRequest, next: Function) => { - if (!this._token) { - return; - } - - if (!request.options.headers) { - request.options.headers = new Headers(); - } - - request.options.headers[this._header] = this._token; - }; - -} diff --git a/test/middleware.ts b/test/middleware.ts deleted file mode 100644 index d3471744e65..00000000000 --- a/test/middleware.ts +++ /dev/null @@ -1,214 +0,0 @@ -import * as chai from 'chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import { cloneDeep } from 'lodash'; - -// make it easy to assert with promises -chai.use(chaiAsPromised); - -const { assert } = chai; - -import { - AuthTokenHeaderMiddleware, - MiddlewareRequest, -} from '../src/middleware'; - -describe('middleware', () => { - describe('AuthTokenHeaderMiddleware', () => { - it('should implement applyMiddleware', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - assert.equal(typeof authMiddleware.applyMiddleware, 'function'); - }); - - it('should create headers and add if none existing', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - authMiddleware.setToken('token'); - - // this is a stub for the end user client api - const middlewareRequest = { - request: { - query: ` - query people($personNum: Int!) { - allPeople(first: $personNum) { - people { - name - } - } - } - `, - variables: {}, - debugName: 'People query', - }, - options: {}, - } as MiddlewareRequest; - - const next = () => { - return; - }; - - const outcome = new Headers(); - outcome['Authorization'] = 'token'; - - authMiddleware.applyMiddleware(middlewareRequest, next); - - assert.deepEqual( - middlewareRequest.options.headers, - outcome - ); - - }); - - it('should add the token to existing headers', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - authMiddleware.setToken('token'); - - const existingHeaders = new Headers(); - existingHeaders['Test'] = 'test'; - - // this is a stub for the end user client api - const middlewareRequest = { - request: { - query: ` - query people($personNum: Int!) { - allPeople(first: $personNum) { - people { - name - } - } - } - `, - variables: {}, - debugName: 'People query', - }, - options: { - headers: existingHeaders, - }, - } as MiddlewareRequest; - - const next = () => { - return; - }; - - const outcome = cloneDeep(existingHeaders); - outcome['Authorization'] = 'token'; - - authMiddleware.applyMiddleware(middlewareRequest, next); - assert.deepEqual( - middlewareRequest.options.headers, - outcome - ); - - }); - - it('should not add the token if no token and no headers', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - - // this is a stub for the end user client api - const middlewareRequest = { - request: { - query: ` - query people($personNum: Int!) { - allPeople(first: $personNum) { - people { - name - } - } - } - `, - variables: {}, - debugName: 'People query', - }, - options: {}, - } as MiddlewareRequest; - - const next = () => { - return; - }; - - authMiddleware.applyMiddleware(middlewareRequest, next); - assert.isUndefined(middlewareRequest.options.headers); - }); - - it('should not add the token if no token and existing headers', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - - const existingHeaders = new Headers(); - existingHeaders['Test'] = 'test'; - - // this is a stub for the end user client api - const middlewareRequest = { - request: { - query: ` - query people($personNum: Int!) { - allPeople(first: $personNum) { - people { - name - } - } - } - `, - variables: {}, - debugName: 'People query', - }, - options: { - headers: existingHeaders, - }, - } as MiddlewareRequest; - - const next = () => { - return; - }; - - authMiddleware.applyMiddleware(middlewareRequest, next); - assert.deepEqual( - middlewareRequest.options.headers, - existingHeaders - ); - }); - - it('should allow setting a custom header', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - assert.equal(typeof authMiddleware.setHeader, 'function'); - }); - - it('should use the custom header instead of default', () => { - const authMiddleware = new AuthTokenHeaderMiddleware(); - authMiddleware.setHeader('Auth-Token'); - authMiddleware.setToken('token-token'); - - // this is a stub for the end user client api - const middlewareRequest = { - request: { - query: ` - query people($personNum: Int!) { - allPeople(first: $personNum) { - people { - name - } - } - } - `, - variables: {}, - debugName: 'People query', - }, - options: {}, - } as MiddlewareRequest; - - const next = () => { - return; - }; - - const outcome = new Headers(); - outcome['Auth-Token'] = 'token-token'; - - authMiddleware.applyMiddleware(middlewareRequest, next); - - assert.deepEqual( - middlewareRequest.options.headers, - outcome - ); - - }); - - }); -}); diff --git a/test/tests.ts b/test/tests.ts index 3ade284e43d..c264c347bd3 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -15,7 +15,6 @@ import './diffAgainstStore'; import './networkInterface'; import './QueryManager'; import './client'; -import './middleware'; import './store'; import './gql'; import './queryTransform';