const { getOperationAST } = require('graphql');

const isSubscription = (operation) => {
  const { query, operationName } = operation;
  const operationAST = getOperationAST(query, operationName);

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

module.exports = isSubscription;

const isSubscriptionDefinition = ({ kind, operation }) => kind === 'OperationDefinition' && operation === 'subscription';

const isSubscription = ({ query }) => query
  && query.definitions
  && query.definitions.some(isSubscriptionDefinition);

module.exports = isSubscription;

remove client side graphql dependency