Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 22 additions & 23 deletions Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down