From d9156acc4647ecd8d2de9deb12dc02b64aa2b64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Velociter?= Date: Fri, 20 Dec 2019 10:43:16 +0100 Subject: [PATCH] Fixes #34: pass query as query string parameter when requested with GET method --- src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index ecee530..ca0c00f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,10 +56,18 @@ export async function getRemoteSchema( { status: 'ok'; schema: string } | { status: 'err'; message: string } > { try { - const { data, errors } = await fetch(endpoint, { + let url = endpoint; + let body: string | undefined = JSON.stringify({ query: introspectionQuery }); + + if (options.method === 'GET') { + endpoint = endpoint + `?query=${encodeURIComponent(introspectionQuery)}`; + body = undefined; + } + + const { data, errors } = await fetch(url, { method: options.method, headers: options.headers, - body: JSON.stringify({ query: introspectionQuery }), + body }).then(res => res.json()) if (errors) {