Skip to content

Commit

Permalink
feat(persisted): useGETForHashedQueries (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Oct 1, 2018
1 parent 37da4f0 commit c205e3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/apollo-angular-link-persisted/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Change log

### v1.2.0
### v1.1.0

- Introduces `useGETForHashedQueries`

### v1.0.0

- Uses `ng-packagr`

### v1.0.0-beta.2

* Adds `sideEffects: false` (webpack) ([PR #580](https://github.com/apollographql/apollo-angular/pull/580))
- Adds `sideEffects: false` (webpack) ([PR #580](https://github.com/apollographql/apollo-angular/pull/580))

### v1.0.0-beta.0

Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular-link-persisted/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "build/bundles/ng.apolloLink.persisted.umd.js",
"module": "build/fesm5/ng.apolloLink.persisted.js",
"typings": "build/ng.apolloLink.persisted.d.ts",
"version": "1.0.0",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "apollographql/apollo-angular"
Expand Down
19 changes: 13 additions & 6 deletions packages/apollo-angular-link-persisted/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import {
} from 'apollo-link-persisted-queries';

export interface Options {
generateHash?: ((document: DocumentNode) => string) | undefined;
disable?: ((error: ErrorResponse) => boolean) | undefined;
generateHash?: ((document: DocumentNode) => string);
disable?: ((error: ErrorResponse) => boolean);
useGETForHashedQueries?: boolean;
}

const transformLink = setContext((_, context) => {
const ctx: any = {};

if (context.http) {
return {
includeQuery: context.http.includeQuery,
includeExtensions: context.http.includeExtensions,
};
ctx.includeQuery = context.http.includeQuery;
ctx.includeExtensions = context.http.includeExtensions;
}

if (context.fetchOptions && context.fetchOptions.method) {
ctx.method = context.fetchOptions.method;
}

return ctx;
});

export const createPersistedQueryLink = (options?: Options) =>
Expand Down
21 changes: 21 additions & 0 deletions packages/apollo-angular-link-persisted/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,25 @@ describe('createPersistedQueryLink', () => {
done();
});
});

test('useGETForHashedQueries', (done: jest.DoneCallback) => {
const execLink = new MockLink();
const spyRequest = jest.spyOn(execLink, 'request').mock;
const link = createPersistedQueryLink({
useGETForHashedQueries: true,
}).concat(execLink);

execute(link, {
query,
}).subscribe(() => {
const op = spyRequest.calls[1][0] as Operation;
const ctx = op.getContext();

// should be compatible with apollo-angular-link-http
expect(ctx.method).toEqual('GET');

// end
done();
});
});
});

0 comments on commit c205e3e

Please sign in to comment.