Hi,
I tried to add a middleware to the networkInterface to check if I can set up withCredentials flag there to support sending Cookies alongside a cross origin graphQL request.
I was following the documentation for Angular 2 here and Apollo Client here but TypeScript complains about this construct:
networkInterface.use({
applyMiddleWare(req, next) => {
console(req, next);
next();
}
});
I am also confused: why providing an object in which a method is called. Second question that came up: From where to import ApplyMiddleWare? I actually only found applyMiddleware (with lowercase a and w) when searching throughout the code. In the example page both variants are used.
I was wondering whether it would be possible to simply allow the withCredentials flag in the FetchOptions on which I found no dedicated documentation.
Help would be highly appreciated as I consider angular2-apollo just the right thing for a big Angular 2 application I am working on according to the descriptions.
Cheers
It should be a arrow function:
networkInterface.use({
applyMiddleWare: (req, next) => {
console(req, next);
next();
}
});
or shorthand function:
networkInterface.use({
applyMiddleWare(req, next) {
console(req, next);
next();
}
});
It also should be provided as an array and the correct name of that method is applyMiddleware:
const mid = {
applyMiddleWare(req, next) {
console(req, next);
next();
}
};
networkInterface.use( [ mid ] );
Following docs from here:
If your GraphQL server and client application are running on different origins, you will get HTTP 405 errors thrown by the client. This happens when recieving the response from the server which is denying the request because of CORS. The client is working as designed. CORS support should be enabled in the apollo-server instance. How to do this is documented in the apollo-server section.
I don't think withCredentials would solve the CORS problem.
@kamilkisiela Thanks for your response.
In your code examples you use applyMiddleWare (upper case W). In the text you mention applyMiddleware (lower case w). 馃槈 So a bit of confusion stays here.
The server already returns the proper handling for CORS but since a cookie is used for some authentication data and the cookie is only sent when withCredentials flag is set it is not enough to only adapt the server.
However for now I used another client to make progress. I will come back to use apollo-client at a later point maybe.
Closing the ticket for now.
Guys, the CORS section isn't present in the docs. How do you get rid of the 405 error?
UPDATE: this fixed my issue https://forums.meteor.com/t/solved-cors-errors-with-apollo-on-meteor-1-4x/29465
Most helpful comment
Guys, the CORS section isn't present in the docs. How do you get rid of the 405 error?
UPDATE: this fixed my issue https://forums.meteor.com/t/solved-cors-errors-with-apollo-on-meteor-1-4x/29465