Skip to content

Commit

Permalink
fix(graphiql): fix operation detection on multi-op documents (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
hos authored and benjie committed Nov 20, 2019
1 parent 8f1ac84 commit 49b2176
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions postgraphiql/src/components/PostGraphiQL.js
@@ -1,6 +1,6 @@
import React from 'react';
import GraphiQL from 'graphiql';
import { parse } from 'graphql';
import { getOperationAST, parse } from 'graphql';
import GraphiQLExplorer from 'graphiql-explorer';
import StorageAPI from 'graphiql/dist/utility/StorageAPI';
import './postgraphiql.css';
Expand Down Expand Up @@ -41,11 +41,13 @@ const defaultQuery = `\
#
`;

const isSubscription = ({ query }) =>
parse(query).definitions.some(
definition =>
definition.kind === 'OperationDefinition' && definition.operation === 'subscription',
);
const isSubscription = ({ query, operationName }) => {
const node = parse(query);

const operation = getOperationAST(node, operationName);

return operation && operation.operation === 'subscription';
};

const {
POSTGRAPHILE_CONFIG = {
Expand Down

0 comments on commit 49b2176

Please sign in to comment.