Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseLoadPayload for POST request #110

Merged
merged 3 commits into from
Mar 14, 2023
Merged

parseLoadPayload for POST request #110

merged 3 commits into from
Mar 14, 2023

Conversation

nycruslan
Copy link
Contributor

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

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • commit message and code follows the Developer's Certification of Origin

Checklist (for documentation change)

  • only relevant documentation part is changed (make a diff before you submit the PR)
  • motivation/reason is provided
  • commit message and code follows the Developer's Certification of Origin

@adrai
Copy link
Member

adrai commented Mar 13, 2023

Why not using the existing request option?

@nycruslan
Copy link
Contributor Author

nycruslan commented Mar 13, 2023

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.

@nycruslan
Copy link
Contributor Author

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.

@phairow
Copy link

phairow commented Mar 13, 2023

Access to namespace and language would allow loading content using post payload rather than url path or using query parameters.

@adrai adrai merged commit 9261fc5 into i18next:master Mar 14, 2023
@adrai
Copy link
Member

adrai commented Mar 14, 2023

included in v2.2.0
thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants