node_modules.graphql.validation.rules.KnownArgumentNames.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-client-maven-plugin Show documentation
Show all versions of apollo-client-maven-plugin Show documentation
Maven plugin for generating graphql clients
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.unknownArgMessage = unknownArgMessage;
exports.unknownDirectiveArgMessage = unknownDirectiveArgMessage;
exports.KnownArgumentNames = KnownArgumentNames;
var _error = require('../../error');
var _suggestionList = require('../../jsutils/suggestionList');
var _suggestionList2 = _interopRequireDefault(_suggestionList);
var _quotedOrList = require('../../jsutils/quotedOrList');
var _quotedOrList2 = _interopRequireDefault(_quotedOrList);
var _kinds = require('../../language/kinds');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function unknownArgMessage(argName, fieldName, typeName, suggestedArgs) {
var message = 'Unknown argument "' + argName + '" on field "' + fieldName + '" of ' + ('type "' + typeName + '".');
if (suggestedArgs.length) {
message += ' Did you mean ' + (0, _quotedOrList2.default)(suggestedArgs) + '?';
}
return message;
} /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* strict
*/
function unknownDirectiveArgMessage(argName, directiveName, suggestedArgs) {
var message = 'Unknown argument "' + argName + '" on directive "@' + directiveName + '".';
if (suggestedArgs.length) {
message += ' Did you mean ' + (0, _quotedOrList2.default)(suggestedArgs) + '?';
}
return message;
}
/**
* Known argument names
*
* A GraphQL field is only valid if all supplied arguments are defined by
* that field.
*/
function KnownArgumentNames(context) {
return {
Argument: function Argument(node, key, parent, path, ancestors) {
var argDef = context.getArgument();
if (!argDef) {
var argumentOf = ancestors[ancestors.length - 1];
if (argumentOf.kind === _kinds.Kind.FIELD) {
var fieldDef = context.getFieldDef();
var parentType = context.getParentType();
if (fieldDef && parentType) {
context.reportError(new _error.GraphQLError(unknownArgMessage(node.name.value, fieldDef.name, parentType.name, (0, _suggestionList2.default)(node.name.value, fieldDef.args.map(function (arg) {
return arg.name;
}))), [node]));
}
} else if (argumentOf.kind === _kinds.Kind.DIRECTIVE) {
var directive = context.getDirective();
if (directive) {
context.reportError(new _error.GraphQLError(unknownDirectiveArgMessage(node.name.value, directive.name, (0, _suggestionList2.default)(node.name.value, directive.args.map(function (arg) {
return arg.name;
}))), [node]));
}
}
}
}
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy