diff --git a/src/index.js b/src/index.js index 0ef1ea9c..889c3b43 100644 --- a/src/index.js +++ b/src/index.js @@ -145,6 +145,11 @@ export type OptionsData = {| * `__typename` field or alternatively calls the `isTypeOf` method). */ typeResolver?: ?GraphQLTypeResolver, + + /** + * A value to pass as subscriptions endpoint. + */ + subscriptionsEndpoint?: ?string, |}; /** @@ -202,6 +207,7 @@ function graphqlHTTP(options: Options): Middleware { let extensionsFn; let showGraphiQL = false; let query; + let subscriptionsEndpoint; let documentAST; let variables; @@ -243,6 +249,7 @@ function graphqlHTTP(options: Options): Middleware { const typeResolver = optionsData.typeResolver; const validationRules = optionsData.validationRules || []; const graphiql = optionsData.graphiql; + subscriptionsEndpoint = optionsData.subscriptionsEndpoint; context = optionsData.context || request; // GraphQL HTTP only supports GET and POST methods. @@ -385,6 +392,7 @@ function graphqlHTTP(options: Options): Middleware { operationName, result, options: typeof showGraphiQL !== 'boolean' ? showGraphiQL : {}, + subscriptionsEndpoint, }); return sendResponse(response, 'text/html', payload); } diff --git a/src/renderGraphiQL.js b/src/renderGraphiQL.js index 36746157..81429324 100644 --- a/src/renderGraphiQL.js +++ b/src/renderGraphiQL.js @@ -15,6 +15,7 @@ type GraphiQLData = {| operationName: ?string, result?: mixed, options: GraphiQLOptions, + subscriptionsEndpoint: ?string, |}; export type GraphiQLOptions = {| @@ -51,6 +52,10 @@ export function renderGraphiQL(data: GraphiQLData): string { : null; const operationName = data.operationName; const defaultQuery = data.options.defaultQuery; + const subscriptionsEndpoint = data.subscriptionsEndpoint + ? data.subscriptionsEndpoint + : 'undefined'; + const subscriptionsEndpointType = typeof subscriptionsEndpoint; return `