Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ The `graphqlHTTP` function accepts the following options:
* **`defaultQuery`**: An optional GraphQL string to use when no query
is provided and no stored query exists from a previous session.
If undefined is provided, GraphiQL will use its own default query.
* **`autoPrettify`**: An optional boolean that when set to true causes the
query to be pretty printed before being displayed.

* **`rootValue`**: A value to pass as the `rootValue` to the `graphql()`
function from [`GraphQL.js/src/execute.js`](https://github.com/graphql/graphql-js/blob/master/src/execution/execute.js#L119).
Expand Down
12 changes: 11 additions & 1 deletion src/renderGraphiQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @flow strict
*/

import { parse, print } from 'graphql';

type GraphiQLData = {|
query: ?string,
variables: ?{ [name: string]: mixed },
Expand All @@ -24,6 +26,11 @@ export type GraphiQLOptions = {|
* will use its own default query.
*/
defaultQuery?: ?string,
/**
* An optional boolean that when set to true causes the query to be pretty
* printed before being displayed.
*/
autoPrettify?: ?boolean,
|};

// Current latest version of GraphiQL.
Expand All @@ -42,7 +49,10 @@ function safeSerialize(data) {
* requested query.
*/
export function renderGraphiQL(data: GraphiQLData): string {
const queryString = data.query;
const queryString =
data.options.autoPrettify && data.query
? print(parse(data.query))
: data.query;
const variablesString = data.variables
? JSON.stringify(data.variables, null, 2)
: null;
Expand Down