Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clientAwareness being undefined in Apollo Link context #212

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Use [`revertable-globals`](https://npm.im/revertable-globals) for tests.
- Removed no longer necessary [`formdata-node`](https://npm.im/formdata-node) workarounds in tests.
- Removed `npm-debug.log` from the `.gitignore` file as npm [v4.2.0](https://github.com/npm/npm/releases/tag/v4.2.0)+ doesn’t create it in the current working directory.
- Support `clientAwareness` being undefined in Apollo Link context, via [#212](https://github.com/jaydenseric/apollo-upload-client/pull/212).

## 14.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/public/createUploadLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = function createUploadLink({
// Apollo Studio client awareness `name` and `version` can be configured
// via `ApolloClient` constructor options:
// https://apollographql.com/docs/studio/client-awareness/#using-apollo-server-and-apollo-client
clientAwareness: { name, version },
clientAwareness: { name, version } = {},
headers,
} = context;

Expand Down
31 changes: 31 additions & 0 deletions test/public/createUploadLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const {
ApolloError,
ApolloLink,
concat,
execute,
gql,
InMemoryCache,
toPromise,
} = require('@apollo/client/core');
const { AbortController, AbortSignal } = require('abort-controller');
const Blob = require('fetch-blob');
Expand Down Expand Up @@ -654,6 +656,35 @@ module.exports = (tests) => {
}
);

tests.add('`createUploadLink` with `execute`.', async () => {
let fetchUri;
let fetchOptions;

const link = createUploadLink({
async fetch(uri, options) {
danielrearden marked this conversation as resolved.
Show resolved Hide resolved
fetchUri = uri;
fetchOptions = options;

return new Response(
JSON.stringify({ data: { a: true } }),
graphqlResponseOptionsOk
);
},
});
const query = '{\n a\n}\n';
const result = await toPromise(execute(link, { query: gql(query) }));

deepStrictEqual(result, {
data: { a: true },
});
strictEqual(fetchUri, defaultUri);
strictEqual(fetchOptions.method, 'POST');
deepStrictEqual(JSON.parse(fetchOptions.body), {
query,
variables: {},
});
});

tests.add('`createUploadLink` with errors, data.', async () => {
let fetchUri;
let fetchOptions;
Expand Down