Skip to content

Commit 5d9aecf

Browse files
feat: Adds specified rules
1 parent 9937a7a commit 5d9aecf

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*
88
* See https://spec.graphql.org/draft/#sec-Directives-Are-Defined
99
*/
10-
func KnownDirectivesRule(context: ValidationContext) -> Visitor {
10+
func KnownDirectivesRule(context: SDLorNormalValidationContext) -> Visitor {
1111
var locationsMap = [String: [String]]()
1212

13-
let schema = context.schema
14-
let definedDirectives = schema.directives
13+
let schema = context.getSchema()
14+
let definedDirectives = schema?.directives ?? specifiedDirectives
1515
for directive in definedDirectives {
1616
locationsMap[directive.name] = directive.locations.map { $0.rawValue }
1717
}

Sources/GraphQL/Validation/Rules/KnownTypeNamesRule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* See https://spec.graphql.org/draft/#sec-Fragment-Spread-Type-Existence
99
*/
10-
func KnownTypeNamesRule(context: ValidationContext) -> Visitor {
10+
func KnownTypeNamesRule(context: SDLorNormalValidationContext) -> Visitor {
1111
let definitions = context.ast.definitions
12-
let existingTypesMap = context.schema.typeMap
12+
let existingTypesMap = context.getSchema()?.typeMap ?? [:]
1313

1414
var typeNames = Set<String>()
1515
for typeName in existingTypesMap.keys {

Sources/GraphQL/Validation/Rules/UniqueArgumentNamesRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* See https://spec.graphql.org/draft/#sec-Argument-Names
99
*/
10-
func UniqueArgumentNamesRule(context: ValidationContext) -> Visitor {
10+
func UniqueArgumentNamesRule(context: ASTValidationContext) -> Visitor {
1111
return Visitor(
1212
enter: { node, _, _, _, _ in
1313
let argumentNodes: [Argument]

Sources/GraphQL/Validation/Rules/UniqueDirectivesPerLocationRule.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*
88
* See https://spec.graphql.org/draft/#sec-Directives-Are-Unique-Per-Location
99
*/
10-
func UniqueDirectivesPerLocationRule(context: ValidationContext) -> Visitor {
10+
func UniqueDirectivesPerLocationRule(context: SDLorNormalValidationContext) -> Visitor {
1111
var uniqueDirectiveMap = [String: Bool]()
1212

13-
let schema = context.schema
14-
let definedDirectives = schema.directives
13+
let schema = context.getSchema()
14+
let definedDirectives = schema?.directives ?? []
1515
for directive in definedDirectives {
1616
uniqueDirectiveMap[directive.name] = !directive.isRepeatable
1717
}

Sources/GraphQL/Validation/Rules/UniqueInputFieldNamesRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* See https://spec.graphql.org/draft/#sec-Input-Object-Field-Uniqueness
99
*/
10-
func UniqueInputFieldNamesRule(context: ValidationContext) -> Visitor {
10+
func UniqueInputFieldNamesRule(context: ASTValidationContext) -> Visitor {
1111
var knownNameStack = [[String: Name]]()
1212
var knownNames = [String: Name]()
1313

Sources/GraphQL/Validation/SpecifiedRules.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,24 @@ public let specifiedRules: [(ValidationContext) -> Visitor] = [
3232
// OverlappingFieldsCanBeMergedRule,
3333
UniqueInputFieldNamesRule,
3434
]
35+
36+
/**
37+
* @internal
38+
*/
39+
public let specifiedSDLRules: [SDLValidationRule] = [
40+
// LoneSchemaDefinitionRule,
41+
// UniqueOperationTypesRule,
42+
// UniqueTypeNamesRule,
43+
// UniqueEnumValueNamesRule,
44+
// UniqueFieldDefinitionNamesRule,
45+
// UniqueArgumentDefinitionNamesRule,
46+
// UniqueDirectiveNamesRule,
47+
KnownTypeNamesRule,
48+
KnownDirectivesRule,
49+
UniqueDirectivesPerLocationRule,
50+
// PossibleTypeExtensionsRule,
51+
// KnownArgumentNamesOnDirectivesRule,
52+
UniqueArgumentNamesRule,
53+
UniqueInputFieldNamesRule,
54+
// ProvidedRequiredArgumentsOnDirectivesRule,
55+
]

0 commit comments

Comments
 (0)