Provide a way to set the fetch()
options in generatePossibleTypes
#1466
Replies: 7 comments
-
Hey @justlevine . I had the impression that CORS should not interfere with server-to-server (host-to-host) requests. Since the request here uses So in that case the You can easily test this locally using the following scripts: const http = require('http');
const server = http.createServer((req, res) => {
res.setHeader('Access-Control-Allow-Origin', 'https://mysite.com');
res.setHeader('Content-Type', 'application/json');
res.write(JSON.stringify({ message: 'Hello, world!' }));
res.end();
});
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
import fetch from 'node-fetch';
fetch('http://localhost:3000/')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
So there is nothing preventing the request from happening. You can perform the introspection request right from your CLI without issues:
|
Beta Was this translation helpful? Give feedback.
-
@theodesp the reason why the origin header isn't set automatically is because of CORS, but Another use case is if you've restricted the entire endpoint to authorized requests only (a core WPGraphQL setting), and therefore need to set an authorization header. |
Beta Was this translation helpful? Give feedback.
-
I think this is a very undocumented feature since most examples mention Browser to Server interactions.
So my suggestion here is to no to use CORS as a security mechanism since it's more confusing. I'm open to further suggestions though. |
Beta Was this translation helpful? Give feedback.
-
To clarify before you close this out, my feature request here is to allow the I then gave two use cases:
Both of these use cases currently break
Whether WPGraphQL should or even can be changed to support differentiating between client/server requests is a much larger conversation, but I think from the perspective of Faust, we should care about current behavior (it currently fails, and user expectation of WPGraphQL CORS 'Limit unauthorized requests' is that it should fail, be it from a browser, an app, or a a node cli command ). If we don't care, the same there's still the auth use case to support this feature request. |
Beta Was this translation helpful? Give feedback.
-
Since this is a CLI command I wonder how it will look like:
or
|
Beta Was this translation helpful? Give feedback.
-
What about if we use Plus it would let us take advantage of type safety, and is a much more future-proof pattern as FaustJS continues to iterate. (Edit: It also could make some of the ApolloClient/auth improvements I've been lobbying for DRYer to implement because the cli and the client headers could theoretically be defined via the same config file). Separately I think being able to pass a custom faust.config to any faust cli command would be a welcome addition, if it's not already supported. |
Beta Was this translation helpful? Give feedback.
-
Will move this to ideas discussion board. |
Beta Was this translation helpful? Give feedback.
-
What
There should be a way to filter the options on the
fetch()
call ingeneratePossibleTypes()
, in order to set things like corsmode
, and headers.Why
I am trying to
generatePossibleTypes()
from mylocalhost
, but I have a CORS policy set on WordPress to limitAccess-Control-Allow-Origin
to a fixed list of domains (e.g.[mysite.com, staging.mysite.com, localhost:3000]
).For that to work I need to change the
fetch()
call to:Alternatives considered.
I can create a custom 'generatePossibleTypes()'. The barrier to entry on this is fairly high, as users expect Faust to 'just work'.
Beta Was this translation helpful? Give feedback.
All reactions