Skip to content

Commit 3cf2dbc

Browse files
Merge pull request #141 from NoDevOrg/swift-5.4
Fix issue with shadow variables in Swift 5.4
2 parents 63c74fa + 2d5433b commit 3cf2dbc

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
runs-on: ubuntu-20.04
7777
strategy:
7878
matrix:
79-
swift: ["5.5", "5.6"]
79+
swift: ["5.4", "5.5", "5.6"]
8080
steps:
8181
- uses: swift-actions/setup-swift@v1
8282
with:

Sources/GraphQL/Validation/Rules/KnownDirectivesRule.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,32 @@ func KnownDirectivesRule(context: ValidationContext) -> Visitor {
2525

2626
return Visitor(
2727
enter: { node, _, _, _, ancestors in
28-
if let node = node as? Directive {
29-
let name = node.name.value
30-
let locations = locationsMap[name]
28+
guard let node = node as? Directive else { return .continue }
3129

32-
guard let locations = locations else {
33-
context.report(
34-
error: GraphQLError(
35-
message: "Unknown directive \"@\(name)\".",
36-
nodes: [node]
37-
)
38-
)
39-
return .continue
40-
}
30+
let name = node.name.value
4131

42-
let candidateLocation = getDirectiveLocationForASTPath(ancestors)
43-
if
44-
let candidateLocation = candidateLocation,
45-
!locations.contains(candidateLocation.rawValue)
46-
{
47-
context.report(
48-
error: GraphQLError(
49-
message: "Directive \"@\(name)\" may not be used on \(candidateLocation.rawValue).",
50-
nodes: [node]
51-
)
32+
guard let locations = locationsMap[name] else {
33+
context.report(
34+
error: GraphQLError(
35+
message: "Unknown directive \"@\(name)\".",
36+
nodes: [node]
5237
)
53-
}
38+
)
39+
return .continue
5440
}
41+
42+
guard
43+
let candidateLocation = getDirectiveLocationForASTPath(ancestors),
44+
!locations.contains(candidateLocation.rawValue)
45+
else { return .continue }
46+
47+
context.report(
48+
error: GraphQLError(
49+
message: "Directive \"@\(name)\" may not be used on \(candidateLocation.rawValue).",
50+
nodes: [node]
51+
)
52+
)
53+
5554
return .continue
5655
}
5756
)

0 commit comments

Comments
 (0)