Skip to content

Commit

Permalink
Use document itself to decide HTTP method for useGETForQueries (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 1, 2020
1 parent 66b77c9 commit e2096e3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/loaders/url/src/index.ts
@@ -1,4 +1,4 @@
import { print, IntrospectionOptions, DocumentNode, GraphQLResolveInfo } from 'graphql';
import { print, IntrospectionOptions, DocumentNode, GraphQLResolveInfo, Kind } from 'graphql';
import {
SchemaPointerSingle,
Source,
Expand Down Expand Up @@ -54,18 +54,17 @@ export class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
useGETForQueries: boolean;
}): AsyncExecutor {
const HTTP_URL = pointer.replace('ws:', 'http:').replace('wss:', 'https:');
return async ({
document,
variables,
info,
}: {
document: DocumentNode;
variables: any;
info: GraphQLResolveInfo;
}) => {
return async ({ document, variables }: { document: DocumentNode; variables: any; info: GraphQLResolveInfo }) => {
let method = defaultMethod;
if (useGETForQueries && info.operation.operation === 'query') {
if (useGETForQueries) {
method = 'GET';
for (const definition of document.definitions) {
if (definition.kind === Kind.OPERATION_DEFINITION) {
if (definition.operation !== 'query') {
method = defaultMethod;
}
}
}
}
const fetchResult = await fetch(HTTP_URL, {
method,
Expand Down

0 comments on commit e2096e3

Please sign in to comment.