From 9bf16e40d74c67781c386be1a4dfdf490e3228c3 Mon Sep 17 00:00:00 2001 From: Andrei Pristavu Date: Wed, 5 Jun 2019 07:26:05 +0300 Subject: [PATCH 1/2] Subscriptions support --- src/index.js | 5 +++++ src/renderGraphiQL.js | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0ef1ea9c..ff8c38c5 100644 --- a/src/index.js +++ b/src/index.js @@ -145,6 +145,8 @@ export type OptionsData = {| * `__typename` field or alternatively calls the `isTypeOf` method). */ typeResolver?: ?GraphQLTypeResolver, + + subscriptionsEndpoint?: ?string, |}; /** @@ -202,6 +204,7 @@ function graphqlHTTP(options: Options): Middleware { let extensionsFn; let showGraphiQL = false; let query; + let subscriptionsEndpoint; let documentAST; let variables; @@ -243,6 +246,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 +389,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 `