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

Commit 9eef4db

Browse files
authored
support default graphiql header state (#796)
1 parent 504ddb7 commit 9eef4db

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ The `graphqlHTTP` function accepts the following options:
136136
- **`headerEditorEnabled`**: An optional boolean which enables the header editor when `true`.
137137
Defaults to `false`.
138138

139+
- **`shouldPersistHeaders`**: An optional boolean which enables headers to be saved to local storage when `true`.
140+
Defaults to `false`.
141+
142+
- **`headers`**: An optional string of initial state for the header editor. Only makes sense if headerEditorEnabled is `true`.
143+
Defaults to empty.
144+
139145
- **`subscriptionEndpoint`**: An optional GraphQL string contains the WebSocket server url for subscription.
140146

141147
- **`websocketClient`**: An optional GraphQL string for websocket client used for subscription, `v0`: subscriptions-transport-ws, `v1`: graphql-ws. Defaults to `v0` if not provided

src/renderGraphiQL.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export interface GraphiQLOptions {
2828
*/
2929
shouldPersistHeaders?: boolean;
3030

31+
/**
32+
* An optional string of initial state for the header editor. Only makes
33+
* sense if headerEditorEnabled is true.
34+
* Defaults to empty.
35+
*/
36+
headers?: string;
37+
3138
/**
3239
* A websocket endpoint for subscription
3340
*/
@@ -71,6 +78,7 @@ export function renderGraphiQL(
7178
const defaultQuery = options?.defaultQuery;
7279
const headerEditorEnabled = options?.headerEditorEnabled;
7380
const shouldPersistHeaders = options?.shouldPersistHeaders;
81+
const headers = options?.headers;
7482
const subscriptionEndpoint = options?.subscriptionEndpoint;
7583
const websocketClient = options?.websocketClient ?? 'v0';
7684

@@ -270,7 +278,8 @@ add "&raw" to the end of the URL within a browser.
270278
operationName: ${safeSerialize(operationName)},
271279
defaultQuery: ${safeSerialize(defaultQuery)},
272280
headerEditorEnabled: ${safeSerialize(headerEditorEnabled)},
273-
shouldPersistHeaders: ${safeSerialize(shouldPersistHeaders)}
281+
shouldPersistHeaders: ${safeSerialize(shouldPersistHeaders)},
282+
headers: ${safeSerialize(headers)}
274283
}),
275284
document.getElementById('graphiql')
276285
);

0 commit comments

Comments
 (0)