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

Added option to disable rewriting URL for GraphiQL #1047

Merged
merged 5 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All of the packages in the `apollo-server` repo are released with the same versi

### vNEXT

* `apollo-server-module-graphiql`: adds an option to the constructor to disable url rewriting when editing a query [PR #1047](https://github.com/apollographql/apollo-server/pull/1047)
* Upgrade `subscription-transport-ws` to 0.9.9 for Graphiql

### v1.3.6
Expand Down
1 change: 1 addition & 0 deletions docs/source/graphiql.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const options = {
result?: Object, // optional result to pre-populate the GraphiQL UI with
passHeader?: String, // a string that will be added to the outgoing request header object (e.g "'Authorization': 'Bearer lorem ipsum'")
editorTheme?: String, // optional CodeMirror theme to be applied to the GraphiQL UI
rewriteURL?: Boolean, // optionally turn off url rewriting when editing queries
}
```

Expand Down
8 changes: 5 additions & 3 deletions packages/apollo-server-module-graphiql/src/renderGraphiQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type GraphiQLData = {
passHeader?: string;
editorTheme?: string;
websocketConnectionParams?: Object;
rewriteURL?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this rewriteURL: boolean = false so it's clearer what the default value is if you don't pass this option?

};

// Current latest version of GraphiQL.
Expand Down Expand Up @@ -62,6 +63,7 @@ export function renderGraphiQL(data: GraphiQLData): string {
const editorTheme = data.editorTheme;
const usingEditorTheme = !!editorTheme;
const websocketConnectionParams = data.websocketConnectionParams || null;
const rewriteURL = !!data.rewriteURL;

/* eslint-disable max-len */
return `
Expand Down Expand Up @@ -199,15 +201,15 @@ export function renderGraphiQL(data: GraphiQLData): string {
// that it can be easily shared.
function onEditQuery(newQuery) {
parameters.query = newQuery;
updateURL();
${rewriteURL ? 'updateURL();' : ''}
}
function onEditVariables(newVariables) {
parameters.variables = newVariables;
updateURL();
${rewriteURL ? 'updateURL();' : ''}
}
function onEditOperationName(newOperationName) {
parameters.operationName = newOperationName;
updateURL();
${rewriteURL ? 'updateURL();' : ''}
}
function updateURL() {
var cleanParams = Object.keys(parameters).filter(function(v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function createGraphiQLData(
passHeader: options.passHeader,
editorTheme: options.editorTheme,
websocketConnectionParams: options.websocketConnectionParams,
rewriteURL: options.rewriteURL,
};
}

Expand Down