Wp-graphql-woocommerce: CORS issue

Created on 3 Feb 2020  ·  7Comments  ·  Source: wp-graphql/wp-graphql-woocommerce

I've just upgraded from WP GraphQL WooCommerce Version 0.2.1 to (WPGraphQL WooCommerce (WooGraphQL) Version 0.4.2) and I am having issues with CORS.

This is the console error I am getting

_Access to fetch at 'https://x.dev/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled._

I have tried these in vain...

a) changing _httpLinkOptions_
credentials: 'same-origin'
to
credentials: 'include'

b) activating and setting wp-graphql-cors plugin

c) setting headers in .htaccess

awaiting author response question

Most helpful comment

@szvest What settings are you using in WPGraphQL-CORS?
In order for the WPGraphQL-CORS to work with WooGraphQL you must have location of the app making the request set in the Extend "Access-Control-Allow-Origin” header option on the WPGraphQL-CORS setting page.

image

You shouldn't use no-cors mode.

All 7 comments

Fixed. It seems that it was an apollo-graphql issue.

Added

fetchOptions: {
    mode: 'no-cors'
  }

to apollo-link-http

@szvest What settings are you using in WPGraphQL-CORS?
In order for the WPGraphQL-CORS to work with WooGraphQL you must have location of the app making the request set in the Extend "Access-Control-Allow-Origin” header option on the WPGraphQL-CORS setting page.

image

You shouldn't use no-cors mode.

Thanks, kidunot89. Much appreciated.

Even with the send site credentials and using the credentials: "include" option the server still sends * as the response for Access-Control-Allow-Origin.

Nevermind had a typo in one of my domains and forgot to include the two // after http:.

how did you install the wp-graphql-cors plugin

I've just upgraded from WP GraphQL WooCommerce Version 0.2.1 to (WPGraphQL WooCommerce (WooGraphQL) Version 0.4.2) and I am having issues with CORS.

This is the console error I am getting

_Access to fetch at 'https://x.dev/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled._

I have tried these in vain...

a) changing _httpLinkOptions_
credentials: 'same-origin'
to
credentials: 'include'

b) activating and setting wp-graphql-cors plugin

c) setting headers in .htaccess

@ebisLab hey dude, did you managed to install this plugin? since I am getting fatal error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mehidi258 picture mehidi258  ·  3Comments

zamson picture zamson  ·  4Comments

pmventura picture pmventura  ·  3Comments

ricokahler picture ricokahler  ·  5Comments

aresrioja10 picture aresrioja10  ·  6Comments