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

fix(graphql): Fixes multiValueHeader handling (and CORS) in graphql handler #5970

Merged
merged 4 commits into from
Jul 19, 2022

Conversation

dac09
Copy link
Collaborator

@dac09 dac09 commented Jul 15, 2022

Fixes #5933

What does this do?

It fixes two different cases where we weren't returning CORS headers.

1. Netlify
Netlify supports multiValueHeaders - but still always returned Access-Control-Allow-Origin: null. That's because in the way we had the logic, the headers in the request (yes, the request) were merged (headers + multiValueHeaders). So if you supply two origins to Yoga, it gets confused and returns null.

This PR makes sure that we only use MVH .... OR ... Headers - not both in the construction of the request, before we pass it to yoga.

2.Vercel
Vercel does not support multiValueHeaders. So in this case, no CORS headers were returned at all. This PR changes it so that we return the headers for the response both as MVH and as regular headers.

@netlify
Copy link

netlify bot commented Jul 15, 2022

Deploy Preview for redwoodjs-docs canceled.

Name Link
🔨 Latest commit d612f2c
🔍 Latest deploy log https://app.netlify.com/sites/redwoodjs-docs/deploys/62d706fbcdefdf00088af368

@dac09 dac09 requested a review from dthyresson July 15, 2022 22:28
@dac09 dac09 added the release:fix This PR is a fix label Jul 15, 2022
@jtoar jtoar self-requested a review July 16, 2022 02:36
Copy link
Contributor

@dthyresson dthyresson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just minor word-smithing.

packages/graphql-server/src/__tests__/cors.test.ts Outdated Show resolved Hide resolved
packages/graphql-server/src/functions/graphql.ts Outdated Show resolved Hide resolved
@dthyresson dthyresson self-requested a review July 19, 2022 16:04
Copy link
Contributor

@jtoar jtoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Awesome work. 🚀 I have no idea how you debugged this one but it looks like it must've been painful—saw some yarn patch action in the PR in deploy target CI so I can only guess haha

@dthyresson dthyresson enabled auto-merge (squash) July 19, 2022 19:33
@dthyresson dthyresson merged commit 0bc9afb into redwoodjs:main Jul 19, 2022
@redwoodjs-bot redwoodjs-bot bot added this to the next-release milestone Jul 19, 2022
@dac09
Copy link
Collaborator Author

dac09 commented Jul 21, 2022

have no idea how you debugged this one

Blood, sweat and tears.... Half the effort was figuring out how to debug it! patch package comes in handy in these situations

dac09 added a commit to dac09/redwood that referenced this pull request Jul 22, 2022
…o feat/ts-strictmode-gen

* 'feat/ts-strictmode-gen' of github.com:dac09/redwood: (94 commits)
  fix(deps): update dependency @graphql-codegen/cli to v2.9.1 (redwoodjs#6013)
  Little grammar change (redwoodjs#6006)
  chore: connect repo to nx cloud to speed up builds (redwoodjs#5988)
  fix(deps): update dependency @testing-library/user-event to v14.3.0 (redwoodjs#6004)
  fix(deps): update graphqlcodegenerator monorepo (redwoodjs#6005)
  chore(deps): update dependency @auth0/auth0-spa-js to v1.22.2 (redwoodjs#6003)
  fix(graphql): Fixes multiValueHeader handling (and CORS) in graphql handler  (redwoodjs#5970)
  chore(deps): update dependency @nhost/hasura-auth-js to v1.4.0 (redwoodjs#6001)
  chore(deps): update dependency @nhost/nhost-js to v1.4.7 (redwoodjs#5999)
  fix(deps): update dependency cross-undici-fetch to v0.4.14 (redwoodjs#6000)
  chore(deps): update dependency @azure/msal-browser to v2.28.0 (redwoodjs#5994)
  fix(deps): update dependency concurrently to v7.3.0 (redwoodjs#5995)
  chore(deps): update dependency @simplewebauthn/browser to v5.3.0 (redwoodjs#5989)
  chore(deps): update dependency @simplewebauthn/server to v5.3.0 (redwoodjs#5990)
  chore(deps): update dependency @simplewebauthn/typescript-types to v5.3.0 (redwoodjs#5991)
  fix(deps): update dependency @testing-library/user-event to v14.2.6 (redwoodjs#5992)
  fix(deps): update typescript-eslint monorepo to v5.30.7 (redwoodjs#5993)
  chore: clean up mock auth client (redwoodjs#5911)
  Adds Webauthn support (TouchID, FaceID) to dbAuth (redwoodjs#5680)
  chore(deps): update dependency octokit to v2.0.4 (redwoodjs#5986)
  ...
jtoar pushed a commit that referenced this pull request Jul 25, 2022
…andler (#5970)

* Add some notes

* fix(headers): Handle when multiValueHeaders are present, and also when they are not

* Update comments

Co-authored-by: David Thyresson <dthyresson@gmail.com>
jtoar pushed a commit that referenced this pull request Jul 28, 2022
…andler (#5970)

* Add some notes

* fix(headers): Handle when multiValueHeaders are present, and also when they are not

* Update comments

Co-authored-by: David Thyresson <dthyresson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
Status: Archived
Development

Successfully merging this pull request may close these issues.

Vercel returning incorrect CORS headers with GraphQL yoga
3 participants