UNPKG

@relay-graphql-js/validation-rules

Version:
32 lines (31 loc) 1.32 kB
"use strict"; exports.__esModule = true; exports.RelayCompatMissingConnectionDirective = void 0; var graphql_1 = require("graphql"); var utils_1 = require("./utils"); function hasAfterArgument(fieldNode) { return !!(fieldNode.arguments && fieldNode.arguments.find(function (arg) { return arg.name.value === "after"; })); } function hasBeforeArgument(fieldNode) { return !!(fieldNode.arguments && fieldNode.arguments.find(function (arg) { return arg.name.value === "before"; })); } // tslint:disable-next-line: no-shadowed-variable exports.RelayCompatMissingConnectionDirective = function RelayCompatMissingConnectionDirective(context) { return { Field: { enter: function (fieldNode) { if (!fieldNode.selectionSet) { return; } var type = context.getType(); if (!type || !utils_1.isConnectionType(type)) { return; } var connectionDirective = utils_1.getConnectionDirective(fieldNode); if (!connectionDirective && (hasAfterArgument(fieldNode) || hasBeforeArgument(fieldNode))) { context.reportError(new graphql_1.GraphQLError("Missing @connection directive", fieldNode)); } } } }; };