SingleFieldSubscriptionsRule.js 867 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.SingleFieldSubscriptionsRule = SingleFieldSubscriptionsRule;
  6. var _GraphQLError = require("../../error/GraphQLError.js");
  7. /**
  8. * Subscriptions must only include one field.
  9. *
  10. * A GraphQL subscription is valid only if it contains a single root field.
  11. */
  12. function SingleFieldSubscriptionsRule(context) {
  13. return {
  14. OperationDefinition: function OperationDefinition(node) {
  15. if (node.operation === 'subscription') {
  16. if (node.selectionSet.selections.length !== 1) {
  17. context.reportError(new _GraphQLError.GraphQLError(node.name ? "Subscription \"".concat(node.name.value, "\" must select only one top level field.") : 'Anonymous Subscription must select only one top level field.', node.selectionSet.selections.slice(1)));
  18. }
  19. }
  20. }
  21. };
  22. }