-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add CSRF token to GraphiQL view #35
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ export function required() { | |
|
||
const GRAPHIQL_VERSION = '0.7.1'; | ||
|
||
export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION } = {}) { | ||
export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION, csrfToken } = {}) { | ||
csrfToken = csrfToken ? `,'x-csrf-token': '${csrfToken}'` : ''; | ||
return ` | ||
<!DOCTYPE html> | ||
<html> | ||
|
@@ -89,7 +90,8 @@ export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION } | |
method: 'post', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Content-Type': 'application/json' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can leave the trailing comma on this line. The main benefit of trailing commas is that they help reduce the size of diffs. This diff section could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CMTegner good points. I don't have time to see this through to completion, as I no longer use this library. |
||
${csrfToken} | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'include', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's usually a good idea to treat function parameters as immutable. In this case a better name could perhaps be
csrfHeader
, as it's more aligned with the actual value.