From 53ab7cc3dd54fc068134ebcb2b83ea39f5455774 Mon Sep 17 00:00:00 2001 From: David Konsumer Date: Fri, 21 Jun 2024 19:33:31 -0700 Subject: [PATCH] add support for POST (#75) --- src/client.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index b7518937..d624a9f1 100644 --- a/src/client.js +++ b/src/client.js @@ -87,7 +87,18 @@ export default class Client { this.caches.set(query, cache); } runQuery(query, variables) { - return this.runUri(this.getGraphqlQuery({ query, variables })); + if ((this.fetchOptions?.method || '').toUpperCase() === 'POST') { + return fetch(this.endpoint, { + ...this.fetchOptions, + headers: { + ...this.fetchOptions?.headers, + 'content-type': 'application/json' + }, + body: JSON.stringify({ query, variables }) + }).then(resp => resp.json()) + } else { + return this.runUri(this.getGraphqlQuery({ query, variables })); + } } runUri(uri) { return fetch(uri, this.fetchOptions || void 0).then(resp => resp.json());