Sha256: 11288b61eb6b8f196192ed150192776fed98aa9e7ccc9a69303156e8abc60d5e

Contents?: true

Size: 1.47 KB

Versions: 26

Compression:

Stored size: 1.47 KB

Contents

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.getOperationRootType = getOperationRootType;

var _GraphQLError = require('../error/GraphQLError.js');

/**
 * Extracts the root type of the operation from the schema.
 *
 * @deprecated Please use `GraphQLSchema.getRootType` instead. Will be removed in v17
 */
function getOperationRootType(schema, operation) {
  if (operation.operation === 'query') {
    const queryType = schema.getQueryType();

    if (!queryType) {
      throw new _GraphQLError.GraphQLError(
        'Schema does not define the required query root type.',
        {
          nodes: operation,
        },
      );
    }

    return queryType;
  }

  if (operation.operation === 'mutation') {
    const mutationType = schema.getMutationType();

    if (!mutationType) {
      throw new _GraphQLError.GraphQLError(
        'Schema is not configured for mutations.',
        {
          nodes: operation,
        },
      );
    }

    return mutationType;
  }

  if (operation.operation === 'subscription') {
    const subscriptionType = schema.getSubscriptionType();

    if (!subscriptionType) {
      throw new _GraphQLError.GraphQLError(
        'Schema is not configured for subscriptions.',
        {
          nodes: operation,
        },
      );
    }

    return subscriptionType;
  }

  throw new _GraphQLError.GraphQLError(
    'Can only have query, mutation and subscription operations.',
    {
      nodes: operation,
    },
  );
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/graphql/utilities/getOperationRootType.js