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

Add headers support to GraphiQL #1016

Merged
merged 7 commits into from Aug 7, 2020

Conversation

radekwlsk
Copy link
Contributor

@radekwlsk radekwlsk commented Jul 31, 2020

  • add GRAPHIQL_HEADER_EDITOR_ENABLED setting with False default
  • use GRAPHIQL_HEADER_EDITOR_ENABLED to set headerEditorEnabled GraphiQL option
  • update graphQLFetcher and httpClient in static/graphiql.js to support custom query/mutation headers

Making use of graphql/graphiql#1543 this PR introduces ability to set custom headers in GraphiQL once GRAPHIQL_HEADER_EDITOR_ENABLED setting is changed to True.

This should resolve #850

Probably some docs for this functionality have to be added (and maybe a test).

* add GRAPHIQL_HEADER_EDITOR_ENABLED setting with False default
* use GRAPHIQL_HEADER_EDITOR_ENABLED to set headerEditorEnabled GraphiQL option
* update graphQLFetcher and httpClient in static/graphiql.js to support custom query/mutation headers
@radekwlsk
Copy link
Contributor Author

@KubaJastrz I've applied your suggestions in 29f28bc

@radekwlsk radekwlsk force-pushed the graphiql-headers branch 3 times, most recently from d89f939 to ca115f5 Compare August 3, 2020 07:52
Comment on lines 44 to 47
# Set to True to enable GraphiQL headers editor tab
# This sets headerEditorEnabled GraphiQL option, for details go to
# https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
"GRAPHIQL_HEADER_EDITOR_ENABLED": False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why not always have it enabled? I think the majority use case for GraphiQL in Django is going to be development, no? Having the header panel always enabled seems like it would be fine. If someone really wants to disable it, they can copy the template and configure GraphiQL themselves.

If we decide to keep it, you'll also need to update views.py to pass through the configuration option like we do with subscription_path as well as the template where it gets injected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not want to enable it by default to not change current behaviour. But I have no objections to make it True by default if that is desired.

I will have a look at views.py and template later today, thanks for info.

Copy link
Collaborator

@eabruzzese eabruzzese Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radekwlsk I love the focus on stability and definitely appreciate the forethought!

Given that GraphiQL is provided by graphene-django as a convenient developer tool outside of the critical path, I don't think it has the same requirements for interface stability as the rest of the library. We upgraded GraphiQL to the latest version very recently in 2.12 which changed the interface quite a bit, and had I known about this feature at the time, I would have just turned it on in that PR (no setting needed at all).

@jkimbo @mvanlonden any feelings on this? Turning it on (always) would make this a very small JS-only PR and one less setting to care about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eabruzzese I've injected the setting to template. With enabling headers tab by default I will let a little bit more discussion to happen first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with enabling the setting by default since it's purely an enhancement and it shouldn't break anything.

Copy link
Member

@jkimbo jkimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great thanks @radekwlsk !

As mentioned I think defaulting the headers setting to True is better.

@radekwlsk
Copy link
Contributor Author

As mentioned I think defaulting the headers setting to True is better.

@jkimbo Should I just flip the default setting to True or remove setting entirely and as @eabruzzese suggested just make the change in JS file?

@jkimbo
Copy link
Member

jkimbo commented Aug 6, 2020

@radekwlsk I think having the setting is good. I would just default it to true

@radekwlsk radekwlsk requested a review from jkimbo August 6, 2020 19:36
graphene_django/static/graphene_django/graphiql.js Outdated Show resolved Hide resolved
graphene_django/templates/graphene/graphiql.html Outdated Show resolved Hide resolved
Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
@jkimbo jkimbo merged commit 55769e8 into graphql-python:master Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add custom header support to GraphiQL
4 participants