Skip to content

Commit

Permalink
Added option to disable rewriting URL for GraphiQL (#1047)
Browse files Browse the repository at this point in the history
* added option to disable rewriting url for graphiql

* updated docs

* added link to PR in changelog
  • Loading branch information
JakeDawkins authored and evans committed Jul 13, 2018
1 parent bf06caf commit b5039f3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
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;
};

// 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

0 comments on commit b5039f3

Please sign in to comment.