[graphiql] HTTP customized headers are not being sent #3029
Replies: 7 comments
-
+1 facing the same issue |
Beta Was this translation helpful? Give feedback.
-
@brettins ran into the same issue, followed an example online that didn't forward the headers from the actual operation in the fetch function. changed const graphqlFetch = (graphqlParams) => {
return fetch(<url>, {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(graphqlParams),
credentials: "same-origin"
}).then((response) => response.json());
} to const graphqlFetch = (graphqlParams, {headers}) => {
return fetch(<url>, {
method: "post",
headers: {
"Content-Type": "application/json",
...headers
},
body: JSON.stringify(graphqlParams),
credentials: "same-origin"
}).then((response) => response.json());
} Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
thank you @dbrrt, this used to be in the readme but we replaced it with the I will remove the @dbbrt's solution above is the appropriate answer, if you're implementing a custom fetcher prop |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I understand how this is not a bug. If the fetch function isn't including headers, then shouldn't that be added in the graphiql code? I'm using a minified version of the graphiql code, I'm not looking to make changes to it to fix it. Maybe I'm misunderstanding how this project is used, as it's simply auto-included for me using API Platform. |
Beta Was this translation helpful? Give feedback.
-
@brettins Bit of a workaround when using API Platform, but if you are using that in combination with Symfony you can override the |
Beta Was this translation helpful? Give feedback.
-
I appreciate the clarification and potential workaround! At this point I'm using graphql playground as it works out of the box. I was excited when I saw that GraphIQl had added a bunch of features that graphql playground had but it looks like I'll just stick with playground until GraphIQl works out of the box. |
Beta Was this translation helpful? Give feedback.
-
Usually a custom I would instead recommend using this approach if you are using a CDN bundle: https://github.com/graphql/graphiql/blob/main/examples/graphiql-cdn/index.html#L60 @brettins this example would be the "out of the box" implementation you are referring to |
Beta Was this translation helpful? Give feedback.
-
Is there an existing issue for this?
Current Behavior
The HTTP authorisation header I have included is not being sent to the GraphQL server.
Expected Behavior
That when I enter something into the "Headers" tab that it is sent to the GraphQL server as a header without any additional steps required.
Steps To Reproduce
Anything else?
Beta Was this translation helpful? Give feedback.
All reactions