Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c765e69

Browse files
committed
Rework AST to be more type safe and allow mutation
Also replace existential types with enums
1 parent 588b7b4 commit c765e69

32 files changed

+4047
-2579
lines changed

‎Sources/GraphQL/Execution/Execute.swift‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,21 @@ func buildExecutionContext(
359359

360360
for definition in documentAST.definitions {
361361
switch definition {
362-
case let definition as OperationDefinition:
362+
case .executableDefinition(.operation(let definition)):
363363
guard !(operationName == nil && possibleOperation != nil) else {
364364
throw GraphQLError(
365365
message: "Must provide operation name if query contains multiple operations."
366366
)
367367
}
368-
368+
369369
if operationName == nil || definition.name?.value == operationName {
370370
possibleOperation = definition
371371
}
372-
373-
case let definition as FragmentDefinition:
372+
case .executableDefinition(.fragment(let definition)):
374373
fragments[definition.name.value] = definition
375-
376374
default:
377375
throw GraphQLError(
378-
message: "GraphQL cannot execute a request containing a \(definition.kind).",
376+
message: "GraphQL cannot execute a request containing a \(definition).",
379377
nodes: [definition]
380378
)
381379
}
@@ -502,7 +500,7 @@ func collectFields(
502500

503501
for selection in selectionSet.selections {
504502
switch selection {
505-
case let field as Field:
503+
case .field(let field):
506504
let shouldInclude = try shouldIncludeNode(
507505
exeContext: exeContext,
508506
directives: field.directives
@@ -519,7 +517,7 @@ func collectFields(
519517
}
520518

521519
fields[name]?.append(field)
522-
case let inlineFragment as InlineFragment:
520+
case .inlineFragment(let inlineFragment):
523521
let shouldInclude = try shouldIncludeNode(
524522
exeContext: exeContext,
525523
directives: inlineFragment.directives
@@ -542,43 +540,41 @@ func collectFields(
542540
fields: &fields,
543541
visitedFragmentNames: &visitedFragmentNames
544542
)
545-
case let fragmentSpread as FragmentSpread:
543+
case .fragmentSpread(let fragmentSpread):
546544
let fragmentName = fragmentSpread.name.value
547-
545+
548546
let shouldInclude = try shouldIncludeNode(
549547
exeContext: exeContext,
550548
directives: fragmentSpread.directives
551549
)
552-
550+
553551
guard visitedFragmentNames[fragmentName] == nil && shouldInclude else {
554552
continue
555553
}
556-
554+
557555
visitedFragmentNames[fragmentName] = true
558-
556+
559557
guard let fragment = exeContext.fragments[fragmentName] else {
560558
continue
561559
}
562-
560+
563561
let fragmentConditionMatches = try doesFragmentConditionMatch(
564562
exeContext: exeContext,
565563
fragment: fragment,
566564
type: runtimeType
567565
)
568-
566+
569567
guard fragmentConditionMatches else {
570568
continue
571569
}
572-
570+
573571
try collectFields(
574572
exeContext: exeContext,
575573
runtimeType: runtimeType,
576574
selectionSet: fragment.selectionSet,
577575
fields: &fields,
578576
visitedFragmentNames: &visitedFragmentNames
579577
)
580-
default:
581-
break
582578
}
583579
}
584580

@@ -629,7 +625,7 @@ func doesFragmentConditionMatch(
629625
return true
630626
}
631627

632-
guard let conditionalType = typeFromAST(schema: exeContext.schema, inputTypeAST: typeConditionAST) else {
628+
guard let conditionalType = typeFromAST(schema: exeContext.schema, inputTypeAST: .namedType(typeConditionAST)) else {
633629
return true
634630
}
635631

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /