Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL fetcher should honor headers from headers editor #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/starlette_graphene3.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ def _inject_file_to_operations(
<link href="//unpkg.com/graphiql/graphiql.css" rel="stylesheet"/>
<script src="//unpkg.com/react@16/umd/react.production.min.js"></script>
<script src="//unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="//unpkg.com/[email protected]/browser/client.js"></script>
<script src="//unpkg.com/[email protected]/browser/client.js"></script>
</head>
<body>
<script src="//unpkg.com/graphiql/graphiql.min.js"></script>
Expand Down Expand Up @@ -588,10 +586,11 @@ def _inject_file_to_operations(
).join('&');

// Defines a GraphQL fetcher using the fetch API.
function graphQLFetcher(graphQLParams) {
function graphQLFetcher(graphQLParams, {headers}) {
var headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...headers,
};
if (csrftoken) {
headers['X-CSRFToken'] = csrftoken;
Expand Down Expand Up @@ -640,11 +639,9 @@ def _inject_file_to_operations(
function updateURL() {
history.replaceState(null, null, locationQuery(parameters));
}
var subscriptionsEndpoint = (location.protocol === 'http:' ? 'ws' : 'wss') + '://' + location.host + location.pathname;
var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(subscriptionsEndpoint, {
reconnect: true
});
var fetcher = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher);
var fetcher = window.GraphiQL.createFetcher({
url: location.protocol + "//" + location.host + location.pathname,
})

// Render <GraphiQL /> into the body.
ReactDOM.render(
Expand Down