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

Issue on version 0.4.8 #52

Closed
eavendano opened this issue Jul 1, 2022 · 8 comments
Closed

Issue on version 0.4.8 #52

eavendano opened this issue Jul 1, 2022 · 8 comments
Assignees

Comments

@eavendano
Copy link

eavendano commented Jul 1, 2022

GET without body

Hello @ardatan! I'm checking the new version 0.4.8 on a Node server. When I did the update from 0.4.7 to 0.4.8 I got a new issue. I got the following code:

  const query = graphql.print(document);
  // console.info('Query: ', query);
  // console.info('Variables: ', variables);
  const fetchResult = await crossFetch.fetch(process.env.GRAPHQL_SERVER, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...context?.headers
    },
    body: JSON.stringify({ query, variables })
  });
  return fetchResult.json();
};

But now when I run the server I have the message showing in my log:

\node_modules\undici\lib\fetch\request.js:437
      throw new TypeError('Request with GET/HEAD method cannot have body.')
            ^

TypeError: Request with GET/HEAD method cannot have body.

On my code I have not changed a single line of code and I just get that error.
Here is the stack trace:

\node_modules\undici\lib\fetch\request.js:437:13
\node_modules\undici\lib\fetch\index.js:114:21
\node_modules\undici\index.js:90:22
\node_modules\cross-undici-fetch\dist\create-node-ponyfill.js:130:16
\node_modules\cross-undici-fetch\dist\create-node-ponyfill.js:125:18
server.js:39:40 <-- This is my code on the line: const fetchResult = await crossFetch.fetch(process.env.GRAPHQL_SERVER, 

Is this a bug or is there something I need to do after the upgrade?

@Destreyf
Copy link

Destreyf commented Jul 1, 2022

I ran into a similar issue, this appears to be tied to the cross-undici-fetch package, but instead with graphql-tools.

@saihaj over at dotansimha/graphql-code-generator#8012 (comment) identified the dependency causing the problem.

You can modify your package.json to get around the issue, for yarn you can add the following:
Copied from @tylermenezes here dotansimha/graphql-code-generator#8012 (comment)

  "resolutions": {
    "undici": "5.5.1"
  }

For npm (requires npm 8.3 or higher) you can do the following, this is how I fixed it for the time being.

{
  ...
  "dependencies": ...
  "devDependencies": ...
  "overrides": {
    "undici": "5.5.1"
   }
}

Hopefully this helps you out as a workaround until undici is fixed.

@eavendano
Copy link
Author

Awesome! It worked for me.

@Destreyf
Copy link

Destreyf commented Jul 2, 2022

@eavendano I don't know that I would have closed this as the problem still exists and all my workaround does is downgrades the version for now. This will still affect everyone using this until they fix the dependency in this package or the upstream undici fixes it's issue.

@eavendano eavendano reopened this Jul 2, 2022
@SimenB
Copy link

SimenB commented Jul 4, 2022

The issue is with cross-undici-fetch's usage of undici.

import { fetch } from 'cross-undici-fetch';

const res = await fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  body: JSON.stringify({
    title: 'foo',
    body: 'bar',
    userId: 1,
  }),
  headers: {
    'Content-type': 'application/json; charset=UTF-8',
  },
});
console.log(await res.text());

This fails with the error from OP. Replace import { fetch } from 'cross-undici-fetch'; with import { fetch } from 'undici'; and it works fine.

@ardatan
Copy link
Owner

ardatan commented Jul 4, 2022

Thanks for the issue! We're on it right now!

@ardatan
Copy link
Owner

ardatan commented Jul 4, 2022

@eavendano
Copy link
Author

Great news! Thanks a log @ardatan! Amazing job my friend.

@SimenB SimenB mentioned this issue Jul 18, 2022
14 tasks
@SimenB
Copy link

SimenB commented Jul 18, 2022

Opened #53 unpinning again, btw

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

No branches or pull requests

4 participants