Skip to content

Commit

Permalink
add support for POST (arackaf#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Jun 22, 2024
1 parent 22ce732 commit 53ab7cc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 53ab7cc

Please sign in to comment.