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

Adding a query key to the request body inserts thousands of query params to the URL #387

Open
Eben-Hafkamp opened this issue Apr 5, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Eben-Hafkamp
Copy link

Eben-Hafkamp commented Apr 5, 2023

I'm passing a graphql query to mande like so:

import { print } from 'graphql';
import { mande, defaults } from 'mande';

// Auth headers code ...

const gql = mande(BASE_URL + API_VER);

export default (query = '', variables = {}) =>
  gql
    .post({
      query: print(query),
      variables,
    })
    .then((res) => res)
    .catch((error) => error);

However for some reason the request that is sent has thousands of parameters added to the url. Is this a conflict in naming? I can't change the convention because the request is consumed by Shopify.

This causes a preflight 414 error code, because the query params are far too long and then there is a resultant CORS issue which I think is a strange side affect error message which will be fixed once the params issue is sorted.

EDIT: I believe the issue is caused by this helper: https://posva.net/mande/mande.options.html. Can you please make it a less generic key, like queryString perhaps.

@Eben-Hafkamp Eben-Hafkamp changed the title Adding a query to the request body insert query params to the URL Adding a query key to the request body inserts thousands of query params to the URL Apr 5, 2023
@posva
Copy link
Owner

posva commented Apr 5, 2023

This is a small bug that reuses the body as options: https://github.com/posva/mande/blob/main/src/index.ts#L263-L266

An easy workaround is to pass an empty first argument post('', { ... })

@posva posva added the bug Something isn't working label Apr 5, 2023
@Eben-Hafkamp
Copy link
Author

Thanks @posva for the workaround suggestion, closing issue.

@posva posva reopened this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants