Skip to content

Commit

Permalink
(graphcache) - fix multipart/graphcache combination (#639)
Browse files Browse the repository at this point in the history
* fix multipart-transformation, extract-files checks for variables.constructor === object

* add changeset

* restore makeDict in normalizeVariables

* add fix in multipart-fetch

* fix linting
  • Loading branch information
JoviDeCroock committed Mar 18, 2020
1 parent a2a3e91 commit d5ec0a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-plants-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@urql/exchange-graphcache': patch
'@urql/exchange-multipart-fetch': patch
---

Fix multipart conversion, in the `extract-files` dependency (used by multipart-fetch) there is an explicit check for the constructor property of an object. This made the files unretrievable.
2 changes: 1 addition & 1 deletion exchanges/graphcache/src/ast/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const filterVariables = (
return undefined;
}

const vars = makeDict();
const vars = {};
for (let i = 0, l = node.variableDefinitions.length; i < l; i++) {
const name = getName(node.variableDefinitions[i].variable);
vars[name] = input[name];
Expand Down
11 changes: 9 additions & 2 deletions exchanges/multipart-fetch/src/multipartFetchExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const createFetchSource = (operation: Operation, shouldUseGet: boolean) => {
: undefined;

const { context } = operation;
const { files } = extractFiles(operation.variables);
// Spreading operation.variables here in case someone made a variables with Object.create(null).
const { files, clone } = extractFiles({ ...operation.variables });

const extraOptions =
typeof context.fetchOptions === 'function'
Expand Down Expand Up @@ -114,7 +115,13 @@ const createFetchSource = (operation: Operation, shouldUseGet: boolean) => {
// Make fetch auto-append this for correctness
delete fetchOptions.headers['content-type'];

fetchOptions.body.append('operations', JSON.stringify(body));
fetchOptions.body.append(
'operations',
JSON.stringify({
...body,
variables: clone,
})
);

const map = {};
let i = 0;
Expand Down

0 comments on commit d5ec0a4

Please sign in to comment.