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

fix(url-loader): send correct data if useGETForQueries is true #1778

Merged
merged 1 commit into from
Jul 14, 2020
Merged
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
35 changes: 26 additions & 9 deletions packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import { print, IntrospectionOptions, DocumentNode, GraphQLResolveInfo, Kind } from 'graphql';
import {
SchemaPointerSingle,
Expand Down Expand Up @@ -101,15 +102,31 @@ export class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
}
}
}
const fetchResult = await fetch(HTTP_URL, {
method,
...(method === 'POST'
? {
body: JSON.stringify({ query: print(document), variables }),
}
: {}),
headers: extraHeaders,
});

let fetchResult: Response;
const query = print(document);
switch (method) {
case 'GET':
const urlObj = new URL(HTTP_URL);
urlObj.searchParams.set('query', query);
urlObj.searchParams.set(variables, JSON.stringify(variables));
const finalUrl = urlObj.toString();
fetchResult = await fetch(finalUrl, {
method: 'GET',
headers: extraHeaders,
});
break;
case 'POST':
fetchResult = await fetch(HTTP_URL, {
method: 'POST',
body: JSON.stringify({
query,
variables,
}),
headers: extraHeaders,
});
break;
}
return fetchResult.json();
};
}
Expand Down