graphql 17.0.0-beta.2 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/__dev__/diagnostics.d.mts +1 -0
- package/__dev__/diagnostics.d.ts +1 -0
- package/__dev__/diagnostics.js +3 -0
- package/__dev__/diagnostics.mjs +3 -0
- package/diagnostics.d.mts +307 -0
- package/diagnostics.d.ts +307 -0
- package/diagnostics.js +75 -0
- package/diagnostics.js.map +1 -0
- package/diagnostics.mjs +70 -0
- package/diagnostics.mjs.map +1 -0
- package/error/GraphQLError.d.mts +3 -1
- package/error/GraphQLError.d.ts +3 -1
- package/error/GraphQLError.js +3 -3
- package/error/GraphQLError.js.map +1 -1
- package/error/GraphQLError.mjs +3 -3
- package/error/GraphQLError.mjs.map +1 -1
- package/error/locatedError.d.mts +1 -3
- package/error/locatedError.d.ts +1 -3
- package/error/locatedError.js.map +1 -1
- package/error/locatedError.mjs.map +1 -1
- package/execution/ExecutionArgs.d.mts +6 -0
- package/execution/ExecutionArgs.d.ts +6 -0
- package/execution/ExecutionArgs.js.map +1 -1
- package/execution/ExecutionArgs.mjs.map +1 -1
- package/execution/Executor.d.mts +19 -1
- package/execution/Executor.d.ts +19 -1
- package/execution/Executor.js +49 -4
- package/execution/Executor.js.map +1 -1
- package/execution/Executor.mjs +49 -4
- package/execution/Executor.mjs.map +1 -1
- package/execution/execute.d.mts +65 -44
- package/execution/execute.d.ts +65 -44
- package/execution/execute.js +73 -4
- package/execution/execute.js.map +1 -1
- package/execution/execute.mjs +73 -4
- package/execution/execute.mjs.map +1 -1
- package/execution/values.d.mts +17 -17
- package/execution/values.d.ts +17 -17
- package/execution/values.js.map +1 -1
- package/execution/values.mjs.map +1 -1
- package/index.d.mts +1 -0
- package/index.d.ts +1 -0
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/language/parser.d.mts +20 -30
- package/language/parser.d.ts +20 -30
- package/language/parser.js +9 -9
- package/language/parser.js.map +1 -1
- package/language/parser.mjs +9 -9
- package/language/parser.mjs.map +1 -1
- package/language/predicates.d.mts +5 -1
- package/language/predicates.d.ts +5 -1
- package/language/predicates.js.map +1 -1
- package/language/predicates.mjs.map +1 -1
- package/language/source.d.mts +4 -5
- package/language/source.d.ts +4 -5
- package/language/source.js.map +1 -1
- package/language/source.mjs.map +1 -1
- package/language/visitor.d.mts +10 -2
- package/language/visitor.d.ts +10 -2
- package/language/visitor.js.map +1 -1
- package/language/visitor.mjs.map +1 -1
- package/package.json +2 -2
- package/type/definition.d.mts +96 -64
- package/type/definition.d.ts +96 -64
- package/type/definition.js.map +1 -1
- package/type/definition.mjs.map +1 -1
- package/type/directives.d.mts +3 -3
- package/type/directives.d.ts +3 -3
- package/type/directives.js.map +1 -1
- package/type/directives.mjs.map +1 -1
- package/type/schema.d.mts +4 -8
- package/type/schema.d.ts +4 -8
- package/type/schema.js.map +1 -1
- package/type/schema.mjs.map +1 -1
- package/type/validate.js +101 -30
- package/type/validate.js.map +1 -1
- package/type/validate.mjs +101 -30
- package/type/validate.mjs.map +1 -1
- package/utilities/TypeInfo.d.mts +1 -1
- package/utilities/TypeInfo.d.ts +1 -1
- package/utilities/TypeInfo.js.map +1 -1
- package/utilities/TypeInfo.mjs.map +1 -1
- package/utilities/buildASTSchema.d.mts +0 -1
- package/utilities/buildASTSchema.d.ts +0 -1
- package/utilities/buildASTSchema.js +0 -1
- package/utilities/buildASTSchema.js.map +1 -1
- package/utilities/buildASTSchema.mjs +0 -1
- package/utilities/buildASTSchema.mjs.map +1 -1
- package/utilities/buildClientSchema.d.mts +5 -1
- package/utilities/buildClientSchema.d.ts +5 -1
- package/utilities/buildClientSchema.js.map +1 -1
- package/utilities/buildClientSchema.mjs.map +1 -1
- package/utilities/coerceInputValue.d.mts +7 -6
- package/utilities/coerceInputValue.d.ts +7 -6
- package/utilities/coerceInputValue.js.map +1 -1
- package/utilities/coerceInputValue.mjs.map +1 -1
- package/utilities/concatAST.d.mts +4 -1
- package/utilities/concatAST.d.ts +4 -1
- package/utilities/concatAST.js.map +1 -1
- package/utilities/concatAST.mjs.map +1 -1
- package/utilities/extendSchema.d.mts +3 -3
- package/utilities/extendSchema.d.ts +3 -3
- package/utilities/extendSchema.js +5 -1
- package/utilities/extendSchema.js.map +1 -1
- package/utilities/extendSchema.mjs +5 -1
- package/utilities/extendSchema.mjs.map +1 -1
- package/utilities/introspectionFromSchema.d.mts +6 -2
- package/utilities/introspectionFromSchema.d.ts +6 -2
- package/utilities/introspectionFromSchema.js.map +1 -1
- package/utilities/introspectionFromSchema.mjs.map +1 -1
- package/utilities/lexicographicSortSchema.d.mts +5 -1
- package/utilities/lexicographicSortSchema.d.ts +5 -1
- package/utilities/lexicographicSortSchema.js.map +1 -1
- package/utilities/lexicographicSortSchema.mjs.map +1 -1
- package/utilities/printSchema.d.mts +5 -1
- package/utilities/printSchema.d.ts +5 -1
- package/utilities/printSchema.js.map +1 -1
- package/utilities/printSchema.mjs.map +1 -1
- package/utilities/replaceVariables.d.mts +4 -8
- package/utilities/replaceVariables.d.ts +4 -8
- package/utilities/replaceVariables.js.map +1 -1
- package/utilities/replaceVariables.mjs.map +1 -1
- package/utilities/stripIgnoredCharacters.d.mts +2 -2
- package/utilities/stripIgnoredCharacters.d.ts +2 -2
- package/utilities/stripIgnoredCharacters.js.map +1 -1
- package/utilities/stripIgnoredCharacters.mjs.map +1 -1
- package/utilities/typeComparators.d.mts +1 -5
- package/utilities/typeComparators.d.ts +1 -5
- package/utilities/typeComparators.js.map +1 -1
- package/utilities/typeComparators.mjs.map +1 -1
- package/utilities/validateInputValue.d.mts +10 -8
- package/utilities/validateInputValue.d.ts +10 -8
- package/utilities/validateInputValue.js.map +1 -1
- package/utilities/validateInputValue.mjs.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.mts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.ts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js +70 -17
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs +70 -17
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.mts +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.ts +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js +90 -21
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs +91 -22
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs.map +1 -1
- package/validation/rules/ExecutableDefinitionsRule.d.mts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.js.map +1 -1
- package/validation/rules/ExecutableDefinitionsRule.mjs.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.mts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.d.mts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.js.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.d.mts +3 -1
- package/validation/rules/KnownArgumentNamesRule.d.ts +3 -1
- package/validation/rules/KnownArgumentNamesRule.js.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/KnownDirectivesRule.js +2 -1
- package/validation/rules/KnownDirectivesRule.js.map +1 -1
- package/validation/rules/KnownDirectivesRule.mjs +2 -1
- package/validation/rules/KnownDirectivesRule.mjs.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.d.mts +3 -1
- package/validation/rules/KnownFragmentNamesRule.d.ts +3 -1
- package/validation/rules/KnownFragmentNamesRule.js.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.d.mts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.js.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.mjs.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.d.mts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.js.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.mjs.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.js.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.mjs.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.d.mts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.d.ts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.js.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.mjs.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUnusedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUnusedVariablesRule.js.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.mjs.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.mts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.d.mts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.js.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.mjs.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.d.mts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.js.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.d.mts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.js.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.mjs.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.js.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.d.mts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.js.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.js.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.d.mts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.js.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.d.mts +3 -1
- package/validation/rules/UniqueOperationNamesRule.d.ts +3 -1
- package/validation/rules/UniqueOperationNamesRule.js.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.d.mts +3 -1
- package/validation/rules/UniqueVariableNamesRule.d.ts +3 -1
- package/validation/rules/UniqueVariableNamesRule.js.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.mjs.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.mts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.d.mts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.js.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.mjs.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.d.mts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.js.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.mts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.mts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs.map +1 -1
- package/validation/validate.d.mts +3 -6
- package/validation/validate.d.ts +3 -6
- package/validation/validate.js +6 -0
- package/validation/validate.js.map +1 -1
- package/validation/validate.mjs +6 -0
- package/validation/validate.mjs.map +1 -1
- package/version.js +2 -2
- package/version.js.map +1 -1
- package/version.mjs +2 -2
- package/version.mjs.map +1 -1
|
@@ -28,14 +28,18 @@ import type { ValidationContext } from "../ValidationContext.js";
|
|
|
28
28
|
* const invalidDocument = parse(`
|
|
29
29
|
* query ($user: User) { field(arg: "1") }
|
|
30
30
|
* `);
|
|
31
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
31
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
32
|
+
* VariablesAreInputTypesRule,
|
|
33
|
+
* ]);
|
|
32
34
|
*
|
|
33
35
|
* invalidErrors.length; // => 1
|
|
34
36
|
*
|
|
35
37
|
* const validDocument = parse(`
|
|
36
38
|
* query ($id: ID) { field(arg: $id) }
|
|
37
39
|
* `);
|
|
38
|
-
* const validErrors = validate(schema, validDocument, [
|
|
40
|
+
* const validErrors = validate(schema, validDocument, [
|
|
41
|
+
* VariablesAreInputTypesRule,
|
|
42
|
+
* ]);
|
|
39
43
|
*
|
|
40
44
|
* validErrors; // => []
|
|
41
45
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablesAreInputTypesRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesAreInputTypesRule.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"VariablesAreInputTypesRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesAreInputTypesRule.ts"],"names":[],"mappings":";;AAyDA,gEAoBC;AA3ED,iEAA2D;AAG3D,0DAAkD;AAGlD,4DAAuD;AAEvD,mEAA6D;AA+C7D,SAAgB,0BAA0B,CACxC,OAA0B;IAE1B,OAAO;QACL,kBAAkB,CAAC,IAA4B;YAC7C,MAAM,IAAI,GAAG,IAAA,4BAAW,EAAC,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAEzD,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAA,2BAAW,EAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC9C,MAAM,QAAQ,GAAG,IAAA,kBAAK,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAElC,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,cAAc,YAAY,+BAA+B,QAAQ,IAAI,EACrE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CACrB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type { VariableDefinitionNode } from '../../language/ast.ts';\nimport { print } from '../../language/printer.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport { isInputType } from '../../type/definition.ts';\n\nimport { typeFromAST } from '../../utilities/typeFromAST.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Variables are input types\n *\n * A GraphQL operation is only valid if all the variables it defines are of\n * input types (scalar, enum, or input object).\n *\n * See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { VariablesAreInputTypesRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * field(arg: ID): String\n * }\n *\n * type User {\n * name: String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * query ($user: User) { field(arg: \"1\") }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * VariablesAreInputTypesRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * query ($id: ID) { field(arg: $id) }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * VariablesAreInputTypesRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function VariablesAreInputTypesRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n VariableDefinition(node: VariableDefinitionNode) {\n const type = typeFromAST(context.getSchema(), node.type);\n\n if (type !== undefined && !isInputType(type)) {\n const variableName = node.variable.name.value;\n const typeName = print(node.type);\n\n context.reportError(\n new GraphQLError(\n `Variable \"$${variableName}\" cannot be non-input type \"${typeName}\".`,\n { nodes: node.type },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablesAreInputTypesRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesAreInputTypesRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAG3D,OAAO,EAAE,KAAK,EAAE,mCAAkC;AAGlD,OAAO,EAAE,WAAW,EAAE,kCAAiC;AAEvD,OAAO,EAAE,WAAW,EAAE,wCAAuC;
|
|
1
|
+
{"version":3,"file":"VariablesAreInputTypesRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesAreInputTypesRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAG3D,OAAO,EAAE,KAAK,EAAE,mCAAkC;AAGlD,OAAO,EAAE,WAAW,EAAE,kCAAiC;AAEvD,OAAO,EAAE,WAAW,EAAE,wCAAuC;AA+C7D,MAAM,UAAU,0BAA0B,CACxC,OAA0B;IAE1B,OAAO;QACL,kBAAkB,CAAC,IAA4B;YAC7C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAEzD,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAElC,OAAO,CAAC,WAAW,CACjB,IAAI,YAAY,CACd,cAAc,YAAY,+BAA+B,QAAQ,IAAI,EACrE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CACrB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type { VariableDefinitionNode } from '../../language/ast.ts';\nimport { print } from '../../language/printer.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport { isInputType } from '../../type/definition.ts';\n\nimport { typeFromAST } from '../../utilities/typeFromAST.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Variables are input types\n *\n * A GraphQL operation is only valid if all the variables it defines are of\n * input types (scalar, enum, or input object).\n *\n * See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { VariablesAreInputTypesRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * field(arg: ID): String\n * }\n *\n * type User {\n * name: String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * query ($user: User) { field(arg: \"1\") }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * VariablesAreInputTypesRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * query ($id: ID) { field(arg: $id) }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * VariablesAreInputTypesRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function VariablesAreInputTypesRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n VariableDefinition(node: VariableDefinitionNode) {\n const type = typeFromAST(context.getSchema(), node.type);\n\n if (type !== undefined && !isInputType(type)) {\n const variableName = node.variable.name.value;\n const typeName = print(node.type);\n\n context.reportError(\n new GraphQLError(\n `Variable \"$${variableName}\" cannot be non-input type \"${typeName}\".`,\n { nodes: node.type },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -23,14 +23,18 @@ import type { ValidationContext } from "../ValidationContext.mjs";
|
|
|
23
23
|
* const invalidDocument = parse(`
|
|
24
24
|
* query ($id: String) { field(arg: $id) }
|
|
25
25
|
* `);
|
|
26
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
26
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* VariablesInAllowedPositionRule,
|
|
28
|
+
* ]);
|
|
27
29
|
*
|
|
28
30
|
* invalidErrors.length; // => 1
|
|
29
31
|
*
|
|
30
32
|
* const validDocument = parse(`
|
|
31
33
|
* query ($id: ID!) { field(arg: $id) }
|
|
32
34
|
* `);
|
|
33
|
-
* const validErrors = validate(schema, validDocument, [
|
|
35
|
+
* const validErrors = validate(schema, validDocument, [
|
|
36
|
+
* VariablesInAllowedPositionRule,
|
|
37
|
+
* ]);
|
|
34
38
|
*
|
|
35
39
|
* validErrors; // => []
|
|
36
40
|
* ```
|
|
@@ -23,14 +23,18 @@ import type { ValidationContext } from "../ValidationContext.js";
|
|
|
23
23
|
* const invalidDocument = parse(`
|
|
24
24
|
* query ($id: String) { field(arg: $id) }
|
|
25
25
|
* `);
|
|
26
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
26
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* VariablesInAllowedPositionRule,
|
|
28
|
+
* ]);
|
|
27
29
|
*
|
|
28
30
|
* invalidErrors.length; // => 1
|
|
29
31
|
*
|
|
30
32
|
* const validDocument = parse(`
|
|
31
33
|
* query ($id: ID!) { field(arg: $id) }
|
|
32
34
|
* `);
|
|
33
|
-
* const validErrors = validate(schema, validDocument, [
|
|
35
|
+
* const validErrors = validate(schema, validDocument, [
|
|
36
|
+
* VariablesInAllowedPositionRule,
|
|
37
|
+
* ]);
|
|
34
38
|
*
|
|
35
39
|
* validErrors; // => []
|
|
36
40
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablesInAllowedPositionRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesInAllowedPositionRule.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"VariablesInAllowedPositionRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesInAllowedPositionRule.ts"],"names":[],"mappings":";;AA6DA,wEAsEC;AA/HD,iEAA2D;AAG3D,sDAA+C;AAI/C,4DAIkC;AAGlC,2EAAqE;AACrE,mEAA6D;AA0C7D,SAAgB,8BAA8B,CAC5C,OAA0B;IAE1B,IAAI,SAA8C,CAAC;IAEnD,OAAO;QACL,mBAAmB,EAAE;YACnB,KAAK;gBACH,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;YACxB,CAAC;YACD,KAAK,CAAC,SAAS;gBACb,MAAM,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC;gBAE7D,KAAK,MAAM,EACT,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,0BAA0B,GAC3B,IAAI,MAAM,EAAE,CAAC;oBACZ,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;oBAEhC,IAAI,MAAM,GAAG,0BAA0B,CAAC;oBACxC,MAAM,KAAK,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;oBAClC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;wBAMnB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;wBACnC,MAAM,OAAO,GAAG,IAAA,4BAAW,EAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;wBACjD,IACE,OAAO;4BACP,CAAC,oBAAoB,CACnB,MAAM,EACN,OAAO,EACP,MAAM,CAAC,YAAY,EACnB,IAAI,EACJ,YAAY,CACb,EACD,CAAC;4BACD,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,cAAc,OAAO,cAAc,OAAO,sCAAsC,IAAI,IAAI,EACxF,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAC1B,CACF,CAA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.ts';\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type { ValueNode, VariableDefinitionNode } from '../../language/ast.ts';\nimport { Kind } from '../../language/kinds.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport type { GraphQLType } from '../../type/definition.ts';\nimport {\n isInputObjectType,\n isNonNullType,\n isNullableType,\n} from '../../type/definition.ts';\nimport type { GraphQLSchema } from '../../type/schema.ts';\n\nimport { isTypeSubTypeOf } from '../../utilities/typeComparators.ts';\nimport { typeFromAST } from '../../utilities/typeFromAST.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Variables in allowed position\n *\n * Variable usages must be compatible with the arguments they are passed to.\n *\n * See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { VariablesInAllowedPositionRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * field(arg: ID!): String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * query ($id: String) { field(arg: $id) }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * VariablesInAllowedPositionRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * query ($id: ID!) { field(arg: $id) }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * VariablesInAllowedPositionRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function VariablesInAllowedPositionRule(\n context: ValidationContext,\n): ASTVisitor {\n let varDefMap: Map<string, VariableDefinitionNode>;\n\n return {\n OperationDefinition: {\n enter() {\n varDefMap = new Map();\n },\n leave(operation) {\n const usages = context.getRecursiveVariableUsages(operation);\n\n for (const {\n node,\n type,\n parentType,\n defaultValue,\n fragmentVariableDefinition,\n } of usages) {\n const varName = node.name.value;\n\n let varDef = fragmentVariableDefinition;\n varDef ??= varDefMap.get(varName);\n if (varDef && type) {\n // A var type is allowed if it is the same or more strict (e.g. is\n // a subtype of) than the expected type. It can be more strict if\n // the variable type is non-null when the expected type is nullable.\n // If both are list types, the variable item type can be more strict\n // than the expected item type (contravariant).\n const schema = context.getSchema();\n const varType = typeFromAST(schema, varDef.type);\n if (\n varType &&\n !allowedVariableUsage(\n schema,\n varType,\n varDef.defaultValue,\n type,\n defaultValue,\n )\n ) {\n context.reportError(\n new GraphQLError(\n `Variable \"$${varName}\" of type \"${varType}\" used in position expecting type \"${type}\".`,\n { nodes: [varDef, node] },\n ),\n );\n }\n\n if (\n isInputObjectType(parentType) &&\n parentType.isOneOf &&\n isNullableType(varType)\n ) {\n context.reportError(\n new GraphQLError(\n `Variable \"$${varName}\" is of type \"${varType}\" but must be non-nullable to be used for OneOf Input Object \"${parentType}\".`,\n { nodes: [varDef, node] },\n ),\n );\n }\n }\n }\n },\n },\n VariableDefinition(node) {\n varDefMap.set(node.variable.name.value, node);\n },\n };\n}\n\n/**\n * Returns true if the variable is allowed in the location it was found,\n * including considering if default values exist for either the variable\n * or the location at which it is located.\n *\n * OneOf Input Object Type fields are considered separately above to\n * provide a more descriptive error message.\n *\n * @internal\n */\nfunction allowedVariableUsage(\n schema: GraphQLSchema,\n varType: GraphQLType,\n varDefaultValue: Maybe<ValueNode>,\n locationType: GraphQLType,\n locationDefaultValue: unknown,\n): boolean {\n if (isNonNullType(locationType) && !isNonNullType(varType)) {\n const hasNonNullVariableDefaultValue =\n varDefaultValue != null && varDefaultValue.kind !== Kind.NULL;\n const hasLocationDefaultValue = locationDefaultValue !== undefined;\n if (!hasNonNullVariableDefaultValue && !hasLocationDefaultValue) {\n return false;\n }\n const nullableLocationType = locationType.ofType;\n return isTypeSubTypeOf(schema, varType, nullableLocationType);\n }\n return isTypeSubTypeOf(schema, varType, locationType);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablesInAllowedPositionRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesInAllowedPositionRule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAG3D,OAAO,EAAE,IAAI,EAAE,iCAAgC;AAI/C,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,kCAAiC;AAGlC,OAAO,EAAE,eAAe,EAAE,4CAA2C;AACrE,OAAO,EAAE,WAAW,EAAE,wCAAuC;
|
|
1
|
+
{"version":3,"file":"VariablesInAllowedPositionRule.js","sourceRoot":"","sources":["../../../src/validation/rules/VariablesInAllowedPositionRule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAG3D,OAAO,EAAE,IAAI,EAAE,iCAAgC;AAI/C,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,kCAAiC;AAGlC,OAAO,EAAE,eAAe,EAAE,4CAA2C;AACrE,OAAO,EAAE,WAAW,EAAE,wCAAuC;AA0C7D,MAAM,UAAU,8BAA8B,CAC5C,OAA0B;IAE1B,IAAI,SAA8C,CAAC;IAEnD,OAAO;QACL,mBAAmB,EAAE;YACnB,KAAK;gBACH,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;YACxB,CAAC;YACD,KAAK,CAAC,SAAS;gBACb,MAAM,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC;gBAE7D,KAAK,MAAM,EACT,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,0BAA0B,GAC3B,IAAI,MAAM,EAAE,CAAC;oBACZ,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;oBAEhC,IAAI,MAAM,GAAG,0BAA0B,CAAC;oBACxC,MAAM,KAAK,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;oBAClC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;wBAMnB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;wBACnC,MAAM,OAAO,GA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AE,CAAC;YAChE,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,oBAAoB,GAAG,YAAY,CAAC,MAAM,CAAC;QACjD,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport type { Maybe } from '../../jsutils/Maybe.ts';\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type { ValueNode, VariableDefinitionNode } from '../../language/ast.ts';\nimport { Kind } from '../../language/kinds.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport type { GraphQLType } from '../../type/definition.ts';\nimport {\n isInputObjectType,\n isNonNullType,\n isNullableType,\n} from '../../type/definition.ts';\nimport type { GraphQLSchema } from '../../type/schema.ts';\n\nimport { isTypeSubTypeOf } from '../../utilities/typeComparators.ts';\nimport { typeFromAST } from '../../utilities/typeFromAST.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Variables in allowed position\n *\n * Variable usages must be compatible with the arguments they are passed to.\n *\n * See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { VariablesInAllowedPositionRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * field(arg: ID!): String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * query ($id: String) { field(arg: $id) }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * VariablesInAllowedPositionRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * query ($id: ID!) { field(arg: $id) }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * VariablesInAllowedPositionRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function VariablesInAllowedPositionRule(\n context: ValidationContext,\n): ASTVisitor {\n let varDefMap: Map<string, VariableDefinitionNode>;\n\n return {\n OperationDefinition: {\n enter() {\n varDefMap = new Map();\n },\n leave(operation) {\n const usages = context.getRecursiveVariableUsages(operation);\n\n for (const {\n node,\n type,\n parentType,\n defaultValue,\n fragmentVariableDefinition,\n } of usages) {\n const varName = node.name.value;\n\n let varDef = fragmentVariableDefinition;\n varDef ??= varDefMap.get(varName);\n if (varDef && type) {\n // A var type is allowed if it is the same or more strict (e.g. is\n // a subtype of) than the expected type. It can be more strict if\n // the variable type is non-null when the expected type is nullable.\n // If both are list types, the variable item type can be more strict\n // than the expected item type (contravariant).\n const schema = context.getSchema();\n const varType = typeFromAST(schema, varDef.type);\n if (\n varType &&\n !allowedVariableUsage(\n schema,\n varType,\n varDef.defaultValue,\n type,\n defaultValue,\n )\n ) {\n context.reportError(\n new GraphQLError(\n `Variable \"$${varName}\" of type \"${varType}\" used in position expecting type \"${type}\".`,\n { nodes: [varDef, node] },\n ),\n );\n }\n\n if (\n isInputObjectType(parentType) &&\n parentType.isOneOf &&\n isNullableType(varType)\n ) {\n context.reportError(\n new GraphQLError(\n `Variable \"$${varName}\" is of type \"${varType}\" but must be non-nullable to be used for OneOf Input Object \"${parentType}\".`,\n { nodes: [varDef, node] },\n ),\n );\n }\n }\n }\n },\n },\n VariableDefinition(node) {\n varDefMap.set(node.variable.name.value, node);\n },\n };\n}\n\n/**\n * Returns true if the variable is allowed in the location it was found,\n * including considering if default values exist for either the variable\n * or the location at which it is located.\n *\n * OneOf Input Object Type fields are considered separately above to\n * provide a more descriptive error message.\n *\n * @internal\n */\nfunction allowedVariableUsage(\n schema: GraphQLSchema,\n varType: GraphQLType,\n varDefaultValue: Maybe<ValueNode>,\n locationType: GraphQLType,\n locationDefaultValue: unknown,\n): boolean {\n if (isNonNullType(locationType) && !isNonNullType(varType)) {\n const hasNonNullVariableDefaultValue =\n varDefaultValue != null && varDefaultValue.kind !== Kind.NULL;\n const hasLocationDefaultValue = locationDefaultValue !== undefined;\n if (!hasNonNullVariableDefaultValue && !hasLocationDefaultValue) {\n return false;\n }\n const nullableLocationType = locationType.ofType;\n return isTypeSubTypeOf(schema, varType, nullableLocationType);\n }\n return isTypeSubTypeOf(schema, varType, locationType);\n}\n"]}
|
|
@@ -39,7 +39,9 @@ import type { ValidationContext } from "../../ValidationContext.mjs";
|
|
|
39
39
|
* const invalidDocument = parse(`
|
|
40
40
|
* { oldName }
|
|
41
41
|
* `);
|
|
42
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
42
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
43
|
+
* NoDeprecatedCustomRule,
|
|
44
|
+
* ]);
|
|
43
45
|
*
|
|
44
46
|
* invalidErrors.length; // => 1
|
|
45
47
|
*
|
|
@@ -39,7 +39,9 @@ import type { ValidationContext } from "../../ValidationContext.js";
|
|
|
39
39
|
* const invalidDocument = parse(`
|
|
40
40
|
* { oldName }
|
|
41
41
|
* `);
|
|
42
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
42
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
43
|
+
* NoDeprecatedCustomRule,
|
|
44
|
+
* ]);
|
|
43
45
|
*
|
|
44
46
|
* invalidErrors.length; // => 1
|
|
45
47
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoDeprecatedCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoDeprecatedCustomRule.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"NoDeprecatedCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoDeprecatedCustomRule.ts"],"names":[],"mappings":";;AA8DA,wDAsDC;AAlHD,oEAA8D;AAI9D,+DAA8E;AAwD9E,SAAgB,sBAAsB,CAAC,OAA0B;IAC/D,OAAO;QACL,KAAK,CAAC,IAAI;YACR,MAAM,QAAQ,GAAG,OAAO,CAAC,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AAC,YAAY,EAAE,CAAC;YAC5C,MAAM,iBAAiB,GAAG,YAAY,EAAE,iBAAiB,CAAC;YAC1D,IAAI,YAAY,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;gBAC9C,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,mBAAmB,YAAY,oBAAoB,iBAAiB,EAAE,EACtE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Custom Rules */\n\nimport { GraphQLError } from '../../../error/GraphQLError.ts';\n\nimport type { ASTVisitor } from '../../../language/visitor.ts';\n\nimport { getNamedType, isInputObjectType } from '../../../type/definition.ts';\n\nimport type { ValidationContext } from '../../ValidationContext.ts';\n\n/**\n * No deprecated\n *\n * A GraphQL document is only valid if all selected fields and all used enum values have not been\n * deprecated.\n *\n * Note: This rule is optional and is not part of the Validation section of the GraphQL\n * Specification. The main purpose of this rule is detection of deprecated usages and not\n * necessarily to forbid their use when querying a service.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import {\n * GraphQLObjectType,\n * GraphQLSchema,\n * GraphQLString,\n * parse,\n * validate,\n * } from 'graphql';\n * import { NoDeprecatedCustomRule } from 'graphql/validation';\n *\n * const schema = new GraphQLSchema({\n * query: new GraphQLObjectType({\n * name: 'Query',\n * fields: {\n * name: { type: GraphQLString },\n * oldName: {\n * type: GraphQLString,\n * deprecationReason: 'Use name instead.',\n * },\n * },\n * }),\n * });\n *\n * const invalidDocument = parse(`\n * { oldName }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * NoDeprecatedCustomRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * { name }\n * `);\n * const validErrors = validate(schema, validDocument, [NoDeprecatedCustomRule]);\n *\n * validErrors; // => []\n * ```\n */\nexport function NoDeprecatedCustomRule(context: ValidationContext): ASTVisitor {\n return {\n Field(node) {\n const fieldDef = context.getFieldDef();\n const deprecationReason = fieldDef?.deprecationReason;\n if (fieldDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The field ${fieldDef} is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n Argument(node) {\n const argDef = context.getArgument();\n const deprecationReason = argDef?.deprecationReason;\n if (argDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The argument \"${argDef}\" is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n ObjectField(node) {\n const inputObjectDef = getNamedType(context.getParentInputType());\n if (isInputObjectType(inputObjectDef)) {\n const inputFieldDef = inputObjectDef.getFields()[node.name.value];\n const deprecationReason = inputFieldDef?.deprecationReason;\n if (deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The input field ${inputFieldDef} is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n }\n },\n EnumValue(node) {\n const enumValueDef = context.getEnumValue();\n const deprecationReason = enumValueDef?.deprecationReason;\n if (enumValueDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The enum value \"${enumValueDef}\" is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoDeprecatedCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoDeprecatedCustomRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,wCAAuC;AAI9D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,qCAAoC;
|
|
1
|
+
{"version":3,"file":"NoDeprecatedCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoDeprecatedCustomRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,wCAAuC;AAI9D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,qCAAoC;AAwD9E,MAAM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,CAAC;YACH,CAAC;QACH,CAAC;QACD,SAAS,CAAC,IAAI;YACZ,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YAC5C,MAAM,iBAAiB,GAAG,YAAY,EAAE,iBAAiB,CAAC;YAC1D,IAAI,YAAY,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;gBAC9C,OAAO,CAAC,WAAW,CACjB,IAAI,YAAY,CACd,mBAAmB,YAAY,oBAAoB,iBAAiB,EAAE,EACtE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Custom Rules */\n\nimport { GraphQLError } from '../../../error/GraphQLError.ts';\n\nimport type { ASTVisitor } from '../../../language/visitor.ts';\n\nimport { getNamedType, isInputObjectType } from '../../../type/definition.ts';\n\nimport type { ValidationContext } from '../../ValidationContext.ts';\n\n/**\n * No deprecated\n *\n * A GraphQL document is only valid if all selected fields and all used enum values have not been\n * deprecated.\n *\n * Note: This rule is optional and is not part of the Validation section of the GraphQL\n * Specification. The main purpose of this rule is detection of deprecated usages and not\n * necessarily to forbid their use when querying a service.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import {\n * GraphQLObjectType,\n * GraphQLSchema,\n * GraphQLString,\n * parse,\n * validate,\n * } from 'graphql';\n * import { NoDeprecatedCustomRule } from 'graphql/validation';\n *\n * const schema = new GraphQLSchema({\n * query: new GraphQLObjectType({\n * name: 'Query',\n * fields: {\n * name: { type: GraphQLString },\n * oldName: {\n * type: GraphQLString,\n * deprecationReason: 'Use name instead.',\n * },\n * },\n * }),\n * });\n *\n * const invalidDocument = parse(`\n * { oldName }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * NoDeprecatedCustomRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * { name }\n * `);\n * const validErrors = validate(schema, validDocument, [NoDeprecatedCustomRule]);\n *\n * validErrors; // => []\n * ```\n */\nexport function NoDeprecatedCustomRule(context: ValidationContext): ASTVisitor {\n return {\n Field(node) {\n const fieldDef = context.getFieldDef();\n const deprecationReason = fieldDef?.deprecationReason;\n if (fieldDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The field ${fieldDef} is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n Argument(node) {\n const argDef = context.getArgument();\n const deprecationReason = argDef?.deprecationReason;\n if (argDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The argument \"${argDef}\" is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n ObjectField(node) {\n const inputObjectDef = getNamedType(context.getParentInputType());\n if (isInputObjectType(inputObjectDef)) {\n const inputFieldDef = inputObjectDef.getFields()[node.name.value];\n const deprecationReason = inputFieldDef?.deprecationReason;\n if (deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The input field ${inputFieldDef} is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n }\n },\n EnumValue(node) {\n const enumValueDef = context.getEnumValue();\n const deprecationReason = enumValueDef?.deprecationReason;\n if (enumValueDef && deprecationReason != null) {\n context.reportError(\n new GraphQLError(\n `The enum value \"${enumValueDef}\" is deprecated. ${deprecationReason}`,\n { nodes: node },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -26,14 +26,18 @@ import type { ValidationContext } from "../../ValidationContext.mjs";
|
|
|
26
26
|
* const invalidDocument = parse(`
|
|
27
27
|
* { __schema { queryType { name } } }
|
|
28
28
|
* `);
|
|
29
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
29
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
30
|
+
* NoSchemaIntrospectionCustomRule,
|
|
31
|
+
* ]);
|
|
30
32
|
*
|
|
31
33
|
* invalidErrors.length; // => 1
|
|
32
34
|
*
|
|
33
35
|
* const validDocument = parse(`
|
|
34
36
|
* { name }
|
|
35
37
|
* `);
|
|
36
|
-
* const validErrors = validate(schema, validDocument, [
|
|
38
|
+
* const validErrors = validate(schema, validDocument, [
|
|
39
|
+
* NoSchemaIntrospectionCustomRule,
|
|
40
|
+
* ]);
|
|
37
41
|
*
|
|
38
42
|
* validErrors; // => []
|
|
39
43
|
* ```
|
|
@@ -26,14 +26,18 @@ import type { ValidationContext } from "../../ValidationContext.js";
|
|
|
26
26
|
* const invalidDocument = parse(`
|
|
27
27
|
* { __schema { queryType { name } } }
|
|
28
28
|
* `);
|
|
29
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
29
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
30
|
+
* NoSchemaIntrospectionCustomRule,
|
|
31
|
+
* ]);
|
|
30
32
|
*
|
|
31
33
|
* invalidErrors.length; // => 1
|
|
32
34
|
*
|
|
33
35
|
* const validDocument = parse(`
|
|
34
36
|
* { name }
|
|
35
37
|
* `);
|
|
36
|
-
* const validErrors = validate(schema, validDocument, [
|
|
38
|
+
* const validErrors = validate(schema, validDocument, [
|
|
39
|
+
* NoSchemaIntrospectionCustomRule,
|
|
40
|
+
* ]);
|
|
37
41
|
*
|
|
38
42
|
* validErrors; // => []
|
|
39
43
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoSchemaIntrospectionCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoSchemaIntrospectionCustomRule.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"NoSchemaIntrospectionCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoSchemaIntrospectionCustomRule.ts"],"names":[],"mappings":";;AAqDA,0EAgBC;AAnED,oEAA8D;AAK9D,+DAA2D;AAC3D,qEAAqE;AA6CrE,SAAgB,+BAA+B,CAC7C,OAA0B;IAE1B,OAAO;QACL,KAAK,CAAC,IAAe;YACnB,MAAM,IAAI,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7C,IAAI,IAAI,IAAI,IAAA,sCAAmB,EAAC,IAAI,CAAC,EAAE,CAAC;gBACtC,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,yFAAyF,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAC5G,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Custom Rules */\n\nimport { GraphQLError } from '../../../error/GraphQLError.ts';\n\nimport type { FieldNode } from '../../../language/ast.ts';\nimport type { ASTVisitor } from '../../../language/visitor.ts';\n\nimport { getNamedType } from '../../../type/definition.ts';\nimport { isIntrospectionType } from '../../../type/introspection.ts';\n\nimport type { ValidationContext } from '../../ValidationContext.ts';\n\n/**\n * Prohibit introspection queries\n *\n * A GraphQL document is only valid if all fields selected are not fields that\n * return an introspection type.\n *\n * Note: This rule is optional and is not part of the Validation section of the\n * GraphQL Specification. This rule effectively disables introspection, which\n * does not reflect best practices and should only be done if absolutely necessary.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { NoSchemaIntrospectionCustomRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * name: String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * { __schema { queryType { name } } }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * NoSchemaIntrospectionCustomRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * { name }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * NoSchemaIntrospectionCustomRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function NoSchemaIntrospectionCustomRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n Field(node: FieldNode) {\n const type = getNamedType(context.getType());\n if (type && isIntrospectionType(type)) {\n context.reportError(\n new GraphQLError(\n `GraphQL introspection has been disabled, but the requested query contained the field \"${node.name.value}\".`,\n { nodes: node },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoSchemaIntrospectionCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoSchemaIntrospectionCustomRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,wCAAuC;AAK9D,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,wCAAuC;
|
|
1
|
+
{"version":3,"file":"NoSchemaIntrospectionCustomRule.js","sourceRoot":"","sources":["../../../../src/validation/rules/custom/NoSchemaIntrospectionCustomRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,wCAAuC;AAK9D,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,wCAAuC;AA6CrE,MAAM,UAAU,+BAA+B,CAC7C,OAA0B;IAE1B,OAAO;QACL,KAAK,CAAC,IAAe;YACnB,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7C,IAAI,IAAI,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtC,OAAO,CAAC,WAAW,CACjB,IAAI,YAAY,CACd,yFAAyF,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAC5G,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Custom Rules */\n\nimport { GraphQLError } from '../../../error/GraphQLError.ts';\n\nimport type { FieldNode } from '../../../language/ast.ts';\nimport type { ASTVisitor } from '../../../language/visitor.ts';\n\nimport { getNamedType } from '../../../type/definition.ts';\nimport { isIntrospectionType } from '../../../type/introspection.ts';\n\nimport type { ValidationContext } from '../../ValidationContext.ts';\n\n/**\n * Prohibit introspection queries\n *\n * A GraphQL document is only valid if all fields selected are not fields that\n * return an introspection type.\n *\n * Note: This rule is optional and is not part of the Validation section of the\n * GraphQL Specification. This rule effectively disables introspection, which\n * does not reflect best practices and should only be done if absolutely necessary.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { buildSchema, parse, validate } from 'graphql';\n * import { NoSchemaIntrospectionCustomRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * name: String\n * }\n * `);\n *\n * const invalidDocument = parse(`\n * { __schema { queryType { name } } }\n * `);\n * const invalidErrors = validate(schema, invalidDocument, [\n * NoSchemaIntrospectionCustomRule,\n * ]);\n *\n * invalidErrors.length; // => 1\n *\n * const validDocument = parse(`\n * { name }\n * `);\n * const validErrors = validate(schema, validDocument, [\n * NoSchemaIntrospectionCustomRule,\n * ]);\n *\n * validErrors; // => []\n * ```\n */\nexport function NoSchemaIntrospectionCustomRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n Field(node: FieldNode) {\n const type = getNamedType(context.getType());\n if (type && isIntrospectionType(type)) {\n context.reportError(\n new GraphQLError(\n `GraphQL introspection has been disabled, but the requested query contained the field \"${node.name.value}\".`,\n { nodes: node },\n ),\n );\n }\n },\n };\n}\n"]}
|
|
@@ -67,12 +67,9 @@ export interface ValidationOptions {
|
|
|
67
67
|
* `);
|
|
68
68
|
* const document = parse('{ missingOne missingTwo }');
|
|
69
69
|
*
|
|
70
|
-
* const errors = validate(
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* [FieldsOnCorrectTypeRule],
|
|
74
|
-
* { maxErrors: 1 },
|
|
75
|
-
* );
|
|
70
|
+
* const errors = validate(schema, document, [FieldsOnCorrectTypeRule], {
|
|
71
|
+
* maxErrors: 1,
|
|
72
|
+
* });
|
|
76
73
|
*
|
|
77
74
|
* errors.length; // => 2
|
|
78
75
|
* errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'
|
package/validation/validate.d.ts
CHANGED
|
@@ -67,12 +67,9 @@ export interface ValidationOptions {
|
|
|
67
67
|
* `);
|
|
68
68
|
* const document = parse('{ missingOne missingTwo }');
|
|
69
69
|
*
|
|
70
|
-
* const errors = validate(
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* [FieldsOnCorrectTypeRule],
|
|
74
|
-
* { maxErrors: 1 },
|
|
75
|
-
* );
|
|
70
|
+
* const errors = validate(schema, document, [FieldsOnCorrectTypeRule], {
|
|
71
|
+
* maxErrors: 1,
|
|
72
|
+
* });
|
|
76
73
|
*
|
|
77
74
|
* errors.length; // => 2
|
|
78
75
|
* errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'
|
package/validation/validate.js
CHANGED
|
@@ -10,11 +10,17 @@ const ast_ts_1 = require("../language/ast.js");
|
|
|
10
10
|
const visitor_ts_1 = require("../language/visitor.js");
|
|
11
11
|
const validate_ts_1 = require("../type/validate.js");
|
|
12
12
|
const TypeInfo_ts_1 = require("../utilities/TypeInfo.js");
|
|
13
|
+
const diagnostics_ts_1 = require("../diagnostics.js");
|
|
13
14
|
const specifiedRules_ts_1 = require("./specifiedRules.js");
|
|
14
15
|
const ValidationContext_ts_1 = require("./ValidationContext.js");
|
|
15
16
|
const QueryDocumentKeysToValidate = (0, mapValue_ts_1.mapValue)(ast_ts_1.QueryDocumentKeys, (keys) => keys.filter((key) => key !== 'description'));
|
|
16
17
|
const tooManyValidationErrorsError = new GraphQLError_ts_1.GraphQLError('Too many validation errors, error limit reached. Validation aborted.');
|
|
17
18
|
function validate(schema, documentAST, rules = specifiedRules_ts_1.specifiedRules, options) {
|
|
19
|
+
return (0, diagnostics_ts_1.shouldTrace)(diagnostics_ts_1.validateChannel)
|
|
20
|
+
? diagnostics_ts_1.validateChannel.traceSync(() => validateImpl(schema, documentAST, rules, options), { schema, document: documentAST })
|
|
21
|
+
: validateImpl(schema, documentAST, rules, options);
|
|
22
|
+
}
|
|
23
|
+
function validateImpl(schema, documentAST, rules, options) {
|
|
18
24
|
const maxErrors = options?.maxErrors ?? 100;
|
|
19
25
|
const hideSuggestions = options?.hideSuggestions ?? false;
|
|
20
26
|
(0, validate_ts_1.assertValidSchema)(schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":";;AAsHA,4BA8CC;AAGD,kCAiBC;AAQD,wCAKC;AAQD,0DAQC;AAnND,wDAAkD;AAGlD,8DAAwD;AAGxD,+CAAuD;AACvD,uDAAgE;AAGhE,qDAAwD;AAExD,0DAAuE;AAEvE,2DAAwE;AAExE,iEAGgC;AAehC,MAAM,2BAA2B,GAAG,IAAA,sBAAQ,EAC1C,0BAAiB,EACjB,CAAC,IAA2B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,aAAa,CAAC,CAC7E,CAAC;AAEF,MAAM,4BAA4B,GAAG,IAAI,8BAAY,CACnD,sEAAsE,CACvE,CAAC;AA2EF,SAAgB,QAAQ,CACtB,MAAqB,EACrB,WAAyB,EACzB,QAAuC,kCAAc,EACrD,OAA2B;IAE3B,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,GAAG,CAAC;IAC5C,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,KAAK,CAAC;IAG1D,IAAA,+BAAiB,EAAC,MAAM,CAAC,CAAC;IAE1B,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,sBAAQ,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,wCAAiB,CACnC,MAAM,EACN,WAAW,EACX,QAAQ,EACR,CAAC,KAAK,EAAE,EAAE;QACR,IAAI,MAAM,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC/B,MAAM,4BAA4B,CAAC;QACrC,CAA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;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAQD,SAAgB,uBAAuB,CACrC,WAAyB,EACzB,MAAqB;IAErB,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["/** @category Validation */\n\nimport { mapValue } from '../jsutils/mapValue.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { DocumentNode } from '../language/ast.ts';\nimport { QueryDocumentKeys } from '../language/ast.ts';\nimport { visit, visitInParallel } from '../language/visitor.ts';\n\nimport type { GraphQLSchema } from '../type/schema.ts';\nimport { assertValidSchema } from '../type/validate.ts';\n\nimport { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.ts';\n\nimport { specifiedRules, specifiedSDLRules } from './specifiedRules.ts';\nimport type { SDLValidationRule, ValidationRule } from './ValidationContext.ts';\nimport {\n SDLValidationContext,\n ValidationContext,\n} from './ValidationContext.ts';\n\n/**\n * Options used when validating a GraphQL document.\n * @category Validation\n */\nexport interface ValidationOptions {\n /** Maximum number of validation errors before validation stops. */\n maxErrors?: number;\n /** Whether suggestion text should be omitted from validation errors. */\n hideSuggestions?: Maybe<boolean>;\n}\n\n// Per the specification, descriptions must not affect validation.\n// See https://spec.graphql.org/draft/#sec-Descriptions\nconst QueryDocumentKeysToValidate = mapValue(\n QueryDocumentKeys,\n (keys: ReadonlyArray<string>) => keys.filter((key) => key !== 'description'),\n);\n\nconst tooManyValidationErrorsError = new GraphQLError(\n 'Too many validation errors, error limit reached. Validation aborted.',\n);\n\n/**\n * Implements the \"Validation\" section of the spec.\n *\n * Validation runs synchronously, returning an array of encountered errors, or\n * an empty array if no errors were encountered and the document is valid.\n *\n * A list of specific validation rules may be provided. If not provided, the\n * default list of rules defined by the GraphQL specification will be used.\n *\n * Each validation rule is a function that returns a visitor\n * (see the language/visitor API). Visitor methods are expected to return\n * GraphQLErrors, or Arrays of GraphQLErrors when invalid.\n *\n * Validate will stop validation after a `maxErrors` limit has been reached.\n * Attackers can send pathologically invalid queries to induce a DoS attack,\n * so `maxErrors` defaults to 100 errors.\n * @param schema - Schema to validate against.\n * @param documentAST - Document AST to validate.\n * @param rules - Validation rules to apply.\n * @param options - Validation options, including error limits and suggestions.\n * @returns Validation errors, or an empty array when the document is valid.\n * @example\n * ```ts\n * // Validate with the default specified rules.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * fullName: String\n * }\n * `);\n *\n * validate(schema, parse('{ greeting }')); // => []\n *\n * const errors = validate(schema, parse('{ missing }'));\n * errors[0].message; // => 'Cannot query field \"missing\" on type \"Query\".'\n * ```\n * @example\n * ```ts\n * // This variant uses a custom rule list and validation options.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { FieldsOnCorrectTypeRule, validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * greeting: String\n * }\n * `);\n * const document = parse('{ missingOne missingTwo }');\n *\n * const errors = validate(\n * schema,\n * document,\n * [FieldsOnCorrectTypeRule],\n * { maxErrors: 1 },\n * );\n *\n * errors.length; // => 2\n * errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'\n *\n * const hiddenSuggestionErrors = validate(\n * schema,\n * parse('{ name }'),\n * [FieldsOnCorrectTypeRule],\n * { hideSuggestions: true },\n * );\n *\n * hiddenSuggestionErrors[0].message; // => 'Cannot query field \"name\" on type \"Query\".'\n * ```\n */\nexport function validate(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule> = specifiedRules,\n options?: ValidationOptions,\n): ReadonlyArray<GraphQLError> {\n const maxErrors = options?.maxErrors ?? 100;\n const hideSuggestions = options?.hideSuggestions ?? false;\n\n // If the schema used for validation is invalid, throw an error.\n assertValidSchema(schema);\n\n const errors: Array<GraphQLError> = [];\n const typeInfo = new TypeInfo(schema);\n const context = new ValidationContext(\n schema,\n documentAST,\n typeInfo,\n (error) => {\n if (errors.length >= maxErrors) {\n throw tooManyValidationErrorsError;\n }\n errors.push(error);\n },\n hideSuggestions,\n );\n\n // This uses a specialized visitor which runs multiple visitors in parallel,\n // while maintaining the visitor skip and break API.\n const visitor = visitInParallel(rules.map((rule) => rule(context)));\n\n // Visit the whole document with each instance of all provided rules.\n try {\n visit(\n documentAST,\n visitWithTypeInfo(typeInfo, visitor),\n QueryDocumentKeysToValidate,\n );\n } catch (e: unknown) {\n if (e === tooManyValidationErrorsError) {\n errors.push(tooManyValidationErrorsError);\n } else {\n throw e;\n }\n }\n return errors;\n}\n\n/** @internal */\nexport function validateSDL(\n documentAST: DocumentNode,\n schemaToExtend?: Maybe<GraphQLSchema>,\n rules: ReadonlyArray<SDLValidationRule> = specifiedSDLRules,\n): ReadonlyArray<GraphQLError> {\n const errors: Array<GraphQLError> = [];\n const context = new SDLValidationContext(\n documentAST,\n schemaToExtend,\n (error) => {\n errors.push(error);\n },\n );\n\n const visitors = rules.map((rule) => rule(context));\n visit(documentAST, visitInParallel(visitors));\n return errors;\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDL(documentAST: DocumentNode): void {\n const errors = validateSDL(documentAST);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDLExtension(\n documentAST: DocumentNode,\n schema: GraphQLSchema,\n): void {\n const errors = validateSDL(documentAST, schema);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":";;AAqHA,4BAYC;AAmDD,kCAiBC;AAQD,wCAKC;AAQD,0DAQC;AAhOD,wDAAkD;AAGlD,8DAAwD;AAGxD,+CAAuD;AACvD,uDAAgE;AAGhE,qDAAwD;AAExD,0DAAuE;AAEvE,sDAAiE;AAEjE,2DAAwE;AAExE,iEAGgC;AAehC,MAAM,2BAA2B,GAAG,IAAA,sBAAQ,EAC1C,0BAAiB,EACjB,CAAC,IAA2B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,aAAa,CAAC,CAC7E,CAAC;AAEF,MAAM,4BAA4B,GAAG,IAAI,8BAAY,CACnD,sEAAsE,CACvE,CAAC;AAwEF,SAAgB,QAAQ,CACtB,MAAqB,EACrB,WAAyB,EACzB,QAAuC,kCAAc,EACrD,OAA2B;IAE3B,OAAO,IAAA,4BAAW,EAAC,gCAAe,CAAC;QACjC,CAAC,CAAC,gCAAe,CAAC,SAAS,CACvB,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,EACvD,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,CAClC;QACH,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,YAAY,CACnB,MAAqB,EACrB,WAAyB,EACzB,KAAoC,EACpC,OAAsC;IAEtC,MAAM,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EAAE;QACR,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAA,kBAAK,EAAC,WAAW,EAAE,IAAA,4BAAe,EAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC;AAQD,SAAgB,cAAc,CAAC,WAAyB;IACtD,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAQD,SAAgB,uBAAuB,CACrC,WAAyB,EACzB,MAAqB;IAErB,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["/** @category Validation */\n\nimport { mapValue } from '../jsutils/mapValue.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { DocumentNode } from '../language/ast.ts';\nimport { QueryDocumentKeys } from '../language/ast.ts';\nimport { visit, visitInParallel } from '../language/visitor.ts';\n\nimport type { GraphQLSchema } from '../type/schema.ts';\nimport { assertValidSchema } from '../type/validate.ts';\n\nimport { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.ts';\n\nimport { shouldTrace, validateChannel } from '../diagnostics.ts';\n\nimport { specifiedRules, specifiedSDLRules } from './specifiedRules.ts';\nimport type { SDLValidationRule, ValidationRule } from './ValidationContext.ts';\nimport {\n SDLValidationContext,\n ValidationContext,\n} from './ValidationContext.ts';\n\n/**\n * Options used when validating a GraphQL document.\n * @category Validation\n */\nexport interface ValidationOptions {\n /** Maximum number of validation errors before validation stops. */\n maxErrors?: number;\n /** Whether suggestion text should be omitted from validation errors. */\n hideSuggestions?: Maybe<boolean>;\n}\n\n// Per the specification, descriptions must not affect validation.\n// See https://spec.graphql.org/draft/#sec-Descriptions\nconst QueryDocumentKeysToValidate = mapValue(\n QueryDocumentKeys,\n (keys: ReadonlyArray<string>) => keys.filter((key) => key !== 'description'),\n);\n\nconst tooManyValidationErrorsError = new GraphQLError(\n 'Too many validation errors, error limit reached. Validation aborted.',\n);\n\n/**\n * Implements the \"Validation\" section of the spec.\n *\n * Validation runs synchronously, returning an array of encountered errors, or\n * an empty array if no errors were encountered and the document is valid.\n *\n * A list of specific validation rules may be provided. If not provided, the\n * default list of rules defined by the GraphQL specification will be used.\n *\n * Each validation rule is a function that returns a visitor\n * (see the language/visitor API). Visitor methods are expected to return\n * GraphQLErrors, or Arrays of GraphQLErrors when invalid.\n *\n * Validate will stop validation after a `maxErrors` limit has been reached.\n * Attackers can send pathologically invalid queries to induce a DoS attack,\n * so `maxErrors` defaults to 100 errors.\n * @param schema - Schema to validate against.\n * @param documentAST - Document AST to validate.\n * @param rules - Validation rules to apply.\n * @param options - Validation options, including error limits and suggestions.\n * @returns Validation errors, or an empty array when the document is valid.\n * @example\n * ```ts\n * // Validate with the default specified rules.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * fullName: String\n * }\n * `);\n *\n * validate(schema, parse('{ greeting }')); // => []\n *\n * const errors = validate(schema, parse('{ missing }'));\n * errors[0].message; // => 'Cannot query field \"missing\" on type \"Query\".'\n * ```\n * @example\n * ```ts\n * // This variant uses a custom rule list and validation options.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { FieldsOnCorrectTypeRule, validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * greeting: String\n * }\n * `);\n * const document = parse('{ missingOne missingTwo }');\n *\n * const errors = validate(schema, document, [FieldsOnCorrectTypeRule], {\n * maxErrors: 1,\n * });\n *\n * errors.length; // => 2\n * errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'\n *\n * const hiddenSuggestionErrors = validate(\n * schema,\n * parse('{ name }'),\n * [FieldsOnCorrectTypeRule],\n * { hideSuggestions: true },\n * );\n *\n * hiddenSuggestionErrors[0].message; // => 'Cannot query field \"name\" on type \"Query\".'\n * ```\n */\nexport function validate(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule> = specifiedRules,\n options?: ValidationOptions,\n): ReadonlyArray<GraphQLError> {\n return shouldTrace(validateChannel)\n ? validateChannel.traceSync(\n () => validateImpl(schema, documentAST, rules, options),\n { schema, document: documentAST },\n )\n : validateImpl(schema, documentAST, rules, options);\n}\n\nfunction validateImpl(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule>,\n options: ValidationOptions | undefined,\n): ReadonlyArray<GraphQLError> {\n const maxErrors = options?.maxErrors ?? 100;\n const hideSuggestions = options?.hideSuggestions ?? false;\n\n // If the schema used for validation is invalid, throw an error.\n assertValidSchema(schema);\n\n const errors: Array<GraphQLError> = [];\n const typeInfo = new TypeInfo(schema);\n const context = new ValidationContext(\n schema,\n documentAST,\n typeInfo,\n (error) => {\n if (errors.length >= maxErrors) {\n throw tooManyValidationErrorsError;\n }\n errors.push(error);\n },\n hideSuggestions,\n );\n\n // This uses a specialized visitor which runs multiple visitors in parallel,\n // while maintaining the visitor skip and break API.\n const visitor = visitInParallel(rules.map((rule) => rule(context)));\n\n // Visit the whole document with each instance of all provided rules.\n try {\n visit(\n documentAST,\n visitWithTypeInfo(typeInfo, visitor),\n QueryDocumentKeysToValidate,\n );\n } catch (e: unknown) {\n if (e === tooManyValidationErrorsError) {\n errors.push(tooManyValidationErrorsError);\n } else {\n throw e;\n }\n }\n return errors;\n}\n\n/** @internal */\nexport function validateSDL(\n documentAST: DocumentNode,\n schemaToExtend?: Maybe<GraphQLSchema>,\n rules: ReadonlyArray<SDLValidationRule> = specifiedSDLRules,\n): ReadonlyArray<GraphQLError> {\n const errors: Array<GraphQLError> = [];\n const context = new SDLValidationContext(\n documentAST,\n schemaToExtend,\n (error) => {\n errors.push(error);\n },\n );\n\n const visitors = rules.map((rule) => rule(context));\n visit(documentAST, visitInParallel(visitors));\n return errors;\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDL(documentAST: DocumentNode): void {\n const errors = validateSDL(documentAST);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDLExtension(\n documentAST: DocumentNode,\n schema: GraphQLSchema,\n): void {\n const errors = validateSDL(documentAST, schema);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n"]}
|
package/validation/validate.mjs
CHANGED
|
@@ -4,11 +4,17 @@ import { QueryDocumentKeys } from "../language/ast.mjs";
|
|
|
4
4
|
import { visit, visitInParallel } from "../language/visitor.mjs";
|
|
5
5
|
import { assertValidSchema } from "../type/validate.mjs";
|
|
6
6
|
import { TypeInfo, visitWithTypeInfo } from "../utilities/TypeInfo.mjs";
|
|
7
|
+
import { shouldTrace, validateChannel } from "../diagnostics.mjs";
|
|
7
8
|
import { specifiedRules, specifiedSDLRules } from "./specifiedRules.mjs";
|
|
8
9
|
import { SDLValidationContext, ValidationContext, } from "./ValidationContext.mjs";
|
|
9
10
|
const QueryDocumentKeysToValidate = mapValue(QueryDocumentKeys, (keys) => keys.filter((key) => key !== 'description'));
|
|
10
11
|
const tooManyValidationErrorsError = new GraphQLError('Too many validation errors, error limit reached. Validation aborted.');
|
|
11
12
|
export function validate(schema, documentAST, rules = specifiedRules, options) {
|
|
13
|
+
return shouldTrace(validateChannel)
|
|
14
|
+
? validateChannel.traceSync(() => validateImpl(schema, documentAST, rules, options), { schema, document: documentAST })
|
|
15
|
+
: validateImpl(schema, documentAST, rules, options);
|
|
16
|
+
}
|
|
17
|
+
function validateImpl(schema, documentAST, rules, options) {
|
|
12
18
|
const maxErrors = options?.maxErrors ?? 100;
|
|
13
19
|
const hideSuggestions = options?.hideSuggestions ?? false;
|
|
14
20
|
assertValidSchema(schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,gCAA+B;AAGlD,OAAO,EAAE,YAAY,EAAE,kCAAiC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,4BAA2B;AACvD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,gCAA+B;AAGhE,OAAO,EAAE,iBAAiB,EAAE,6BAA4B;AAExD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kCAAiC;AAEvE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,6BAA4B;AAExE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAClB,gCAA+B;AAehC,MAAM,2BAA2B,GAAG,QAAQ,CAC1C,iBAAiB,EACjB,CAAC,IAA2B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,aAAa,CAAC,CAC7E,CAAC;AAEF,MAAM,4BAA4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IAE3D,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,oBAAoB,CACtC,WAAW,EACX,cAAc,EACd,CAAC,KAAK,EAAE,EAAE;QACR,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,KAAK,CAAC,WAAW,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC;AAQD,MAAM,UAAU,cAAc,CAAC,WAAyB;IACtD,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,uBAAuB,CACrC,WAAyB,EACzB,MAAqB;IAErB,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["/** @category Validation */\n\nimport { mapValue } from '../jsutils/mapValue.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { DocumentNode } from '../language/ast.ts';\nimport { QueryDocumentKeys } from '../language/ast.ts';\nimport { visit, visitInParallel } from '../language/visitor.ts';\n\nimport type { GraphQLSchema } from '../type/schema.ts';\nimport { assertValidSchema } from '../type/validate.ts';\n\nimport { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.ts';\n\nimport { specifiedRules, specifiedSDLRules } from './specifiedRules.ts';\nimport type { SDLValidationRule, ValidationRule } from './ValidationContext.ts';\nimport {\n SDLValidationContext,\n ValidationContext,\n} from './ValidationContext.ts';\n\n/**\n * Options used when validating a GraphQL document.\n * @category Validation\n */\nexport interface ValidationOptions {\n /** Maximum number of validation errors before validation stops. */\n maxErrors?: number;\n /** Whether suggestion text should be omitted from validation errors. */\n hideSuggestions?: Maybe<boolean>;\n}\n\n// Per the specification, descriptions must not affect validation.\n// See https://spec.graphql.org/draft/#sec-Descriptions\nconst QueryDocumentKeysToValidate = mapValue(\n QueryDocumentKeys,\n (keys: ReadonlyArray<string>) => keys.filter((key) => key !== 'description'),\n);\n\nconst tooManyValidationErrorsError = new GraphQLError(\n 'Too many validation errors, error limit reached. Validation aborted.',\n);\n\n/**\n * Implements the \"Validation\" section of the spec.\n *\n * Validation runs synchronously, returning an array of encountered errors, or\n * an empty array if no errors were encountered and the document is valid.\n *\n * A list of specific validation rules may be provided. If not provided, the\n * default list of rules defined by the GraphQL specification will be used.\n *\n * Each validation rule is a function that returns a visitor\n * (see the language/visitor API). Visitor methods are expected to return\n * GraphQLErrors, or Arrays of GraphQLErrors when invalid.\n *\n * Validate will stop validation after a `maxErrors` limit has been reached.\n * Attackers can send pathologically invalid queries to induce a DoS attack,\n * so `maxErrors` defaults to 100 errors.\n * @param schema - Schema to validate against.\n * @param documentAST - Document AST to validate.\n * @param rules - Validation rules to apply.\n * @param options - Validation options, including error limits and suggestions.\n * @returns Validation errors, or an empty array when the document is valid.\n * @example\n * ```ts\n * // Validate with the default specified rules.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * fullName: String\n * }\n * `);\n *\n * validate(schema, parse('{ greeting }')); // => []\n *\n * const errors = validate(schema, parse('{ missing }'));\n * errors[0].message; // => 'Cannot query field \"missing\" on type \"Query\".'\n * ```\n * @example\n * ```ts\n * // This variant uses a custom rule list and validation options.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { FieldsOnCorrectTypeRule, validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * greeting: String\n * }\n * `);\n * const document = parse('{ missingOne missingTwo }');\n *\n * const errors = validate(\n * schema,\n * document,\n * [FieldsOnCorrectTypeRule],\n * { maxErrors: 1 },\n * );\n *\n * errors.length; // => 2\n * errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'\n *\n * const hiddenSuggestionErrors = validate(\n * schema,\n * parse('{ name }'),\n * [FieldsOnCorrectTypeRule],\n * { hideSuggestions: true },\n * );\n *\n * hiddenSuggestionErrors[0].message; // => 'Cannot query field \"name\" on type \"Query\".'\n * ```\n */\nexport function validate(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule> = specifiedRules,\n options?: ValidationOptions,\n): ReadonlyArray<GraphQLError> {\n const maxErrors = options?.maxErrors ?? 100;\n const hideSuggestions = options?.hideSuggestions ?? false;\n\n // If the schema used for validation is invalid, throw an error.\n assertValidSchema(schema);\n\n const errors: Array<GraphQLError> = [];\n const typeInfo = new TypeInfo(schema);\n const context = new ValidationContext(\n schema,\n documentAST,\n typeInfo,\n (error) => {\n if (errors.length >= maxErrors) {\n throw tooManyValidationErrorsError;\n }\n errors.push(error);\n },\n hideSuggestions,\n );\n\n // This uses a specialized visitor which runs multiple visitors in parallel,\n // while maintaining the visitor skip and break API.\n const visitor = visitInParallel(rules.map((rule) => rule(context)));\n\n // Visit the whole document with each instance of all provided rules.\n try {\n visit(\n documentAST,\n visitWithTypeInfo(typeInfo, visitor),\n QueryDocumentKeysToValidate,\n );\n } catch (e: unknown) {\n if (e === tooManyValidationErrorsError) {\n errors.push(tooManyValidationErrorsError);\n } else {\n throw e;\n }\n }\n return errors;\n}\n\n/** @internal */\nexport function validateSDL(\n documentAST: DocumentNode,\n schemaToExtend?: Maybe<GraphQLSchema>,\n rules: ReadonlyArray<SDLValidationRule> = specifiedSDLRules,\n): ReadonlyArray<GraphQLError> {\n const errors: Array<GraphQLError> = [];\n const context = new SDLValidationContext(\n documentAST,\n schemaToExtend,\n (error) => {\n errors.push(error);\n },\n );\n\n const visitors = rules.map((rule) => rule(context));\n visit(documentAST, visitInParallel(visitors));\n return errors;\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDL(documentAST: DocumentNode): void {\n const errors = validateSDL(documentAST);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDLExtension(\n documentAST: DocumentNode,\n schema: GraphQLSchema,\n): void {\n const errors = validateSDL(documentAST, schema);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,gCAA+B;AAGlD,OAAO,EAAE,YAAY,EAAE,kCAAiC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,4BAA2B;AACvD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,gCAA+B;AAGhE,OAAO,EAAE,iBAAiB,EAAE,6BAA4B;AAExD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kCAAiC;AAEvE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,2BAA0B;AAEjE,OAAO,EAAE,cAAc,EAAE,iBAAiB,E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AC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,uBAAuB,CACrC,WAAyB,EACzB,MAAqB;IAErB,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["/** @category Validation */\n\nimport { mapValue } from '../jsutils/mapValue.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { DocumentNode } from '../language/ast.ts';\nimport { QueryDocumentKeys } from '../language/ast.ts';\nimport { visit, visitInParallel } from '../language/visitor.ts';\n\nimport type { GraphQLSchema } from '../type/schema.ts';\nimport { assertValidSchema } from '../type/validate.ts';\n\nimport { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.ts';\n\nimport { shouldTrace, validateChannel } from '../diagnostics.ts';\n\nimport { specifiedRules, specifiedSDLRules } from './specifiedRules.ts';\nimport type { SDLValidationRule, ValidationRule } from './ValidationContext.ts';\nimport {\n SDLValidationContext,\n ValidationContext,\n} from './ValidationContext.ts';\n\n/**\n * Options used when validating a GraphQL document.\n * @category Validation\n */\nexport interface ValidationOptions {\n /** Maximum number of validation errors before validation stops. */\n maxErrors?: number;\n /** Whether suggestion text should be omitted from validation errors. */\n hideSuggestions?: Maybe<boolean>;\n}\n\n// Per the specification, descriptions must not affect validation.\n// See https://spec.graphql.org/draft/#sec-Descriptions\nconst QueryDocumentKeysToValidate = mapValue(\n QueryDocumentKeys,\n (keys: ReadonlyArray<string>) => keys.filter((key) => key !== 'description'),\n);\n\nconst tooManyValidationErrorsError = new GraphQLError(\n 'Too many validation errors, error limit reached. Validation aborted.',\n);\n\n/**\n * Implements the \"Validation\" section of the spec.\n *\n * Validation runs synchronously, returning an array of encountered errors, or\n * an empty array if no errors were encountered and the document is valid.\n *\n * A list of specific validation rules may be provided. If not provided, the\n * default list of rules defined by the GraphQL specification will be used.\n *\n * Each validation rule is a function that returns a visitor\n * (see the language/visitor API). Visitor methods are expected to return\n * GraphQLErrors, or Arrays of GraphQLErrors when invalid.\n *\n * Validate will stop validation after a `maxErrors` limit has been reached.\n * Attackers can send pathologically invalid queries to induce a DoS attack,\n * so `maxErrors` defaults to 100 errors.\n * @param schema - Schema to validate against.\n * @param documentAST - Document AST to validate.\n * @param rules - Validation rules to apply.\n * @param options - Validation options, including error limits and suggestions.\n * @returns Validation errors, or an empty array when the document is valid.\n * @example\n * ```ts\n * // Validate with the default specified rules.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * fullName: String\n * }\n * `);\n *\n * validate(schema, parse('{ greeting }')); // => []\n *\n * const errors = validate(schema, parse('{ missing }'));\n * errors[0].message; // => 'Cannot query field \"missing\" on type \"Query\".'\n * ```\n * @example\n * ```ts\n * // This variant uses a custom rule list and validation options.\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { FieldsOnCorrectTypeRule, validate } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * greeting: String\n * }\n * `);\n * const document = parse('{ missingOne missingTwo }');\n *\n * const errors = validate(schema, document, [FieldsOnCorrectTypeRule], {\n * maxErrors: 1,\n * });\n *\n * errors.length; // => 2\n * errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'\n *\n * const hiddenSuggestionErrors = validate(\n * schema,\n * parse('{ name }'),\n * [FieldsOnCorrectTypeRule],\n * { hideSuggestions: true },\n * );\n *\n * hiddenSuggestionErrors[0].message; // => 'Cannot query field \"name\" on type \"Query\".'\n * ```\n */\nexport function validate(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule> = specifiedRules,\n options?: ValidationOptions,\n): ReadonlyArray<GraphQLError> {\n return shouldTrace(validateChannel)\n ? validateChannel.traceSync(\n () => validateImpl(schema, documentAST, rules, options),\n { schema, document: documentAST },\n )\n : validateImpl(schema, documentAST, rules, options);\n}\n\nfunction validateImpl(\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules: ReadonlyArray<ValidationRule>,\n options: ValidationOptions | undefined,\n): ReadonlyArray<GraphQLError> {\n const maxErrors = options?.maxErrors ?? 100;\n const hideSuggestions = options?.hideSuggestions ?? false;\n\n // If the schema used for validation is invalid, throw an error.\n assertValidSchema(schema);\n\n const errors: Array<GraphQLError> = [];\n const typeInfo = new TypeInfo(schema);\n const context = new ValidationContext(\n schema,\n documentAST,\n typeInfo,\n (error) => {\n if (errors.length >= maxErrors) {\n throw tooManyValidationErrorsError;\n }\n errors.push(error);\n },\n hideSuggestions,\n );\n\n // This uses a specialized visitor which runs multiple visitors in parallel,\n // while maintaining the visitor skip and break API.\n const visitor = visitInParallel(rules.map((rule) => rule(context)));\n\n // Visit the whole document with each instance of all provided rules.\n try {\n visit(\n documentAST,\n visitWithTypeInfo(typeInfo, visitor),\n QueryDocumentKeysToValidate,\n );\n } catch (e: unknown) {\n if (e === tooManyValidationErrorsError) {\n errors.push(tooManyValidationErrorsError);\n } else {\n throw e;\n }\n }\n return errors;\n}\n\n/** @internal */\nexport function validateSDL(\n documentAST: DocumentNode,\n schemaToExtend?: Maybe<GraphQLSchema>,\n rules: ReadonlyArray<SDLValidationRule> = specifiedSDLRules,\n): ReadonlyArray<GraphQLError> {\n const errors: Array<GraphQLError> = [];\n const context = new SDLValidationContext(\n documentAST,\n schemaToExtend,\n (error) => {\n errors.push(error);\n },\n );\n\n const visitors = rules.map((rule) => rule(context));\n visit(documentAST, visitInParallel(visitors));\n return errors;\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDL(documentAST: DocumentNode): void {\n const errors = validateSDL(documentAST);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n\n/**\n * Utility function which asserts a SDL document is valid by throwing an error\n * if it is invalid.\n *\n * @internal\n */\nexport function assertValidSDLExtension(\n documentAST: DocumentNode,\n schema: GraphQLSchema,\n): void {\n const errors = validateSDL(documentAST, schema);\n if (errors.length !== 0) {\n throw new Error(errors.map((error) => error.message).join('\\n\\n'));\n }\n}\n"]}
|
package/version.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.versionInfo = exports.version = void 0;
|
|
4
|
-
exports.version = '17.0.0
|
|
4
|
+
exports.version = '17.0.0';
|
|
5
5
|
exports.versionInfo = Object.freeze({
|
|
6
6
|
major: 17,
|
|
7
7
|
minor: 0,
|
|
8
8
|
patch: 0,
|
|
9
|
-
preReleaseTag:
|
|
9
|
+
preReleaseTag: null,
|
|
10
10
|
});
|
|
11
11
|
//# sourceMappingURL=version.js.map
|
package/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAMa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAMa,QAAA,OAAO,GAAG,QAAkB,CAAC;AAG7B,QAAA,WAAW,GAKnB,MAAM,CAAC,MAAM,CAAC;IACjB,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,IAAI;CACpB,CAAC,CAAC","sourcesContent":["/** @category Version */\n\n// Note: This file is autogenerated using \"resources/gen-version.js\" script and\n// automatically updated by \"npm version\" command.\n\n/** A string containing the version of the GraphQL.js library */\nexport const version = '17.0.0' as string;\n\n/** An object containing the components of the GraphQL.js version string */\nexport const versionInfo: Readonly<{\n major: number;\n minor: number;\n patch: number;\n preReleaseTag: string | null;\n}> = Object.freeze({\n major: 17,\n minor: 0,\n patch: 0,\n preReleaseTag: null,\n});\n"]}
|
package/version.mjs
CHANGED
package/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAkB,CAAC;AAG1C,MAAM,CAAC,MAAM,WAAW,GAKnB,MAAM,CAAC,MAAM,CAAC;IACjB,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,IAAI;CACpB,CAAC,CAAC","sourcesContent":["/** @category Version */\n\n// Note: This file is autogenerated using \"resources/gen-version.js\" script and\n// automatically updated by \"npm version\" command.\n\n/** A string containing the version of the GraphQL.js library */\nexport const version = '17.0.0' as string;\n\n/** An object containing the components of the GraphQL.js version string */\nexport const versionInfo: Readonly<{\n major: number;\n minor: number;\n patch: number;\n preReleaseTag: string | null;\n}> = Object.freeze({\n major: 17,\n minor: 0,\n patch: 0,\n preReleaseTag: null,\n});\n"]}
|