diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 491d2aaa..da53fb30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,7 +76,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - swift: ["5.5", "5.6"] + swift: ["5.4", "5.5", "5.6"] steps: - uses: swift-actions/setup-swift@v1 with: diff --git a/Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift b/Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift index 5d893520..18be3c0a 100644 --- a/Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift +++ b/Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift @@ -25,33 +25,32 @@ func KnownDirectivesRule(context: ValidationContext) -> Visitor { return Visitor( enter: { node, _, _, _, ancestors in - if let node = node as? Directive { - let name = node.name.value - let locations = locationsMap[name] + guard let node = node as? Directive else { return .continue } - guard let locations = locations else { - context.report( - error: GraphQLError( - message: "Unknown directive \"@\(name)\".", - nodes: [node] - ) - ) - return .continue - } + let name = node.name.value - let candidateLocation = getDirectiveLocationForASTPath(ancestors) - if - let candidateLocation = candidateLocation, - !locations.contains(candidateLocation.rawValue) - { - context.report( - error: GraphQLError( - message: "Directive \"@\(name)\" may not be used on \(candidateLocation.rawValue).", - nodes: [node] - ) + guard let locations = locationsMap[name] else { + context.report( + error: GraphQLError( + message: "Unknown directive \"@\(name)\".", + nodes: [node] ) - } + ) + return .continue } + + guard + let candidateLocation = getDirectiveLocationForASTPath(ancestors), + !locations.contains(candidateLocation.rawValue) + else { return .continue } + + context.report( + error: GraphQLError( + message: "Directive \"@\(name)\" may not be used on \(candidateLocation.rawValue).", + nodes: [node] + ) + ) + return .continue } )