Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

[RFC] GraphiQL when loaded in browser #16

Merged
merged 1 commit into from
Sep 29, 2015
Merged

[RFC] GraphiQL when loaded in browser #16

merged 1 commit into from
Sep 29, 2015

Conversation

leebyron
Copy link
Contributor

This RFC adds an opt-in behavior of express-graphql to render a fully functional GraphiQL instance when loaded from a browser - determed as anything that prefers HTML over JSON from the Accept header.

GraphiQL mode is enabled by providing graphiql: true in the options bag. It defaults to false which is a reasonable default, but also ensures any existing use updating to this version will not unknowingly add this feature. The examples in the README have been changed to enable GraphiQL, ideally all future users will leave this on, cargo-cult from README is likely.

When GraphiQL is shown, the query result is run on the server first and presented immediately in the GraphiQL UI.

If you wish to use the browser as a cheap cURL, just add &raw to the end of the URL and GraphiQL is replaced by raw JSON output.

One small detail: any non-GraphQL GET params provided will be carried through by GraphiQL when executing queries. Ideally this covers the majority of authentication cases which are likely to look something like https://mysite/graphql?oauth=abc123&query={yo}.

@leebyron
Copy link
Contributor Author

This Good Idea™ comes from @steveluscher

and as a result has been presented GraphiQL - an in-browser IDE for
exploring GraphQL.

If you wish to receive JSON, provide the header "Accept: application/json".
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention raw here.

@dschafer
Copy link
Contributor

Looks good. Ship it.

This RFC adds an opt-in behavior of express-graphql to render a fully functional GraphiQL instance when loaded from a browser - determed as anything that prefers HTML over JSON from the Accept header.

GraphiQL mode is enabled by providing `graphiql: true` in the options bag. It defaults to `false` which is a reasonable default, but also ensures any existing use updating to this version will not unknowingly add this feature. The examples in the README have been changed to enable GraphiQL, ideally all future users will leave this on, cargo-cult from README is likely.

When GraphiQL is shown, the query result is run on the server first and presented immediately in the GraphiQL UI.

If you wish to use the browser as a cheap cURL, just add `&raw` to the end of the URL and GraphiQL is replaced by raw JSON output.

One small detail: any non-GraphQL GET params provided will be carried through by GraphiQL when executing queries. Ideally this covers the majority of authentication cases where are likely to look something like `https://mysite/graphql?oauth=abc123&query={yo}`.
leebyron added a commit that referenced this pull request Sep 29, 2015
[RFC] GraphiQL when loaded in browser
@leebyron leebyron merged commit 412470c into master Sep 29, 2015
@leebyron leebyron deleted the graphiql branch September 29, 2015 23:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants