Apollo Client is not accepting CORS from SpringBoot graphQL server in TEST environment

Our Apollo client doesn’t want to accept CORS coming from the SpringBoot graphQL server in our TEST environment. It doesn’t have a problem with it when running the ReactJS app and SpringBoot locally. I’ve tried configuring the HttpLink in several different ways without success. This is what I currently have configured and it doesn’t like that either. Any suggestions would be greatly appreciated.

const httpLink = new HttpLink({ uri: testURL,
headers: {
‘Access-Control-Allow-Origin’: ‘*’,
‘cookie’: ‘glooenv=gloocookie’,
‘api-key’: 'abc123}
});

const client = new ApolloClient({
cache: new InMemoryCache(),
fetchOptions: {
mode: ‘no-cors’,
},
link: httpLink
});

As you are using headers that are not on the CORS safelist, you will not be able to use mode: 'no-cors'.

If your server is on another domain, you will likely have to use mode: 'cors'.

After that, there is nothing to do on the Apollo Client side.
CORS is configured on the server - it’s a security mechanism between the user’s browser and the server. No JavaScript on the client has any influence on that.
=> You will have to configure your server correctly, there is nothing you can do about this on the client.

That also means that you can (and should) stop sending this Access-Control-Allow-Origin to your server. That’s a header the server has to send to the browser, not the other way round.

Including credentials is the only thing that worked. More documentation around this issue is warranted.

const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
‘api-key’: abc123
},
});
return forward(operation);
}
);

const httpLink = new HttpLink({
uri: graphQLUrl,
credentials: ‘include’,
});

const link = ApolloLink.from([authMiddleware, httpLink]);

const client = new ApolloClient({
link: link,
cache,
fetchOptions: {
mode: ‘cors’
}
});