Skip to content

Commit

Permalink
- update graphql fetcher to set the url and variables from the Graphi…
Browse files Browse the repository at this point in the history
…QL Component and pass it as queryParams to the GET request
  • Loading branch information
jasonbahl committed Dec 20, 2023
1 parent f4f99c7 commit cb6e9e3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions components/MiniGraphiQL.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,22 @@ const MiniGraphiQLClient = ({ initialQuery, initialVariables, endpoint, readOnly
const fetcher = createGraphiQLFetcher({
url: endpoint,
fetch: async (url, options) => {
// Construct query parameters
const params = new URLSearchParams({
query: options.body.query,
variables: JSON.stringify(options.body.variables),
});
const parsedBody = JSON.parse(options?.body);

const params = new URLSearchParams();
params.append('query', parsedBody.query);
if (options.body.variables) {
params.append('variables', JSON.stringify(parsedBody.variables));
}
const getUrl = `${url}&${params.toString()}`;

// Make the GET request
return fetch(`${url}?${params.toString()}`, {
const res = await fetch(getUrl, {
method: 'GET',
headers: { 'Accept': 'application/json' }
headers: options?.headers,
});

return res;
}
});

Expand Down

0 comments on commit cb6e9e3

Please sign in to comment.