Closed nycruslan closed 1 year ago
Why not using the existing request option?
That's a good question.
When working with GraphQL would be convenient to have access to the namespaces and languages for generating a correct GraphQL POST request.
Here is a simple use case for this:
{
loadPath: url.toString(),
parseLoadPayload([locale]: string[], [ns]: string[]) {
const { variables } = graphqlVariables(ns);
const query = queries[ns];
const graphqlQuery = {
query,
variables: {
locale,
...variables,
},
};
return graphqlQuery;
},
parse(resp: string) {
const { data } = JSON.parse(resp);
return data;
},
}
I considered updating the request function to access namespaces and languages, but it will require significant updates and may cause breaking changes. Same with parsePayload.
The request function definitely works when using additional HTTP clients like Apollo Client or Axios to make a POST request.
But since requestOptions is making a POST request, this update could be a nice addition.
Access to namespace and language would allow loading content using post payload rather than url path or using query parameters.
included in v2.2.0 thank you for your contribution
Adding parseLoadPayload for POST request.
For everybody working with GraphQL or who would like to send a POST request - the parseLoadPayload function will be handy. It gets access to languages and namespaces and can parse the data before it has been sent by loadPath.
Checklist
npm run test
Checklist (for documentation change)