UNPKG

@neo4j/graphql

Version:

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations

71 lines 3.54 kB
"use strict"; /* * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidateNeo4jDirectiveArgumentsValue = ValidateNeo4jDirectiveArgumentsValue; const directives_1 = require("../../../graphql/directives"); const validation_error_codes_1 = require("../utils/validation-error-codes"); const document_validation_error_1 = require("./utils/document-validation-error"); const path_parser_1 = require("./utils/path-parser"); const utils_1 = require("./utils/utils"); function ValidateNeo4jDirectiveArgumentsValue(context) { const schema = context.getSchema(); if (!schema) { throw new Error("Validation error: schema is not available"); } return { Directive(directiveNode, _key, _parent, path, ancestors) { const neo4jDirectiveToValidate = [ directives_1.fulltextDirective.name, directives_1.relationshipDirective.name, directives_1.nodeDirective.name, directives_1.customResolverDirective.name, directives_1.cypherDirective.name, ].find((applicableDirectiveName) => directiveNode.name.value.toLowerCase() === applicableDirectiveName.toLowerCase()); if (!neo4jDirectiveToValidate) { return; } const directiveDefinition = schema.getDirective(directiveNode.name.value); const directiveName = directiveNode.name.value; if (!directiveDefinition) { // Do not report, delegate this report to KnownDirectivesRule return; } const pathToHere = [...(0, path_parser_1.getPathToNode)(path, ancestors)[0], `@${directiveName}`]; for (const argument of directiveNode.arguments ?? []) { const argumentDefinition = (0, utils_1.findArgumentDefinitionNodeByName)(directiveDefinition.args, argument.name.value); if (!argumentDefinition) { return; // If argument name is not found, delegate to KnownArgumentNamesRule } const { isValid, errorMsg, errorPath } = (0, utils_1.assertArgumentType)(argument, argumentDefinition); if (!isValid) { context.reportError((0, document_validation_error_1.createGraphQLError)({ nodes: [argument, directiveNode], path: [...pathToHere, argument.name.value, ...errorPath], errorMsg: `Invalid argument: ${argument.name.value}, error: ${errorMsg}`, extensions: { exception: { code: validation_error_codes_1.VALIDATION_ERROR_CODES[directiveName.toUpperCase()] }, }, })); } } }, }; } //# sourceMappingURL=validate-neo4j-directive-arguments-value.js.map