-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed ordering of sorted selections for merged fields * WIP: Creating ASTField * Invert ASTField and ASTFieldType * rename object to entity, as it can be an object, interface, or union * More renames * Fix equality * Refactor to expose GraphQLType
- Loading branch information
1 parent
b843c2a
commit 6d057c7
Showing
11 changed files
with
205 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Foundation | ||
|
||
@dynamicMemberLookup | ||
struct ASTField: Equatable { | ||
enum FieldType: Equatable { | ||
case scalar(GraphQLType) | ||
case entity(EntityFieldData) | ||
} | ||
|
||
struct EntityFieldData: Equatable { | ||
let type: GraphQLType | ||
let selectionSet: CompilationResult.SelectionSet | ||
let enclosingEntityMergedSelectionBuilder: MergedSelectionBuilder | ||
} | ||
|
||
let underlyingField: CompilationResult.Field | ||
let type: FieldType | ||
|
||
init(_ field: CompilationResult.Field, | ||
enclosingScopeMergedSelectionBuilder: MergedSelectionBuilder? = nil) { | ||
self.underlyingField = field | ||
self.type = FieldType( | ||
self.underlyingField, | ||
enclosingScopeMergedSelectionBuilder: enclosingScopeMergedSelectionBuilder | ||
) | ||
} | ||
|
||
subscript<V>(dynamicMember keyPath: KeyPath<CompilationResult.Field, V>) -> V { | ||
get { | ||
underlyingField[keyPath: keyPath] | ||
} | ||
} | ||
|
||
static func ==(lhs: ASTField, rhs: ASTField) -> Bool { | ||
lhs.underlyingField == rhs.underlyingField && | ||
lhs.type == rhs.type | ||
} | ||
} | ||
|
||
extension ASTField.FieldType { | ||
init(_ field: CompilationResult.Field, | ||
enclosingScopeMergedSelectionBuilder: MergedSelectionBuilder?) { | ||
switch field.type.namedType { | ||
case is GraphQLScalarType, is GraphQLEnumType: | ||
self = .scalar(field.type) | ||
|
||
case is GraphQLCompositeType: | ||
guard let selectionSet = field.selectionSet else { | ||
fatalError("Invalid field: \(field). An object type field must contain a selection set.") | ||
} | ||
guard let enclosingScopeMergedSelectionBuilder = enclosingScopeMergedSelectionBuilder else { | ||
fatalError("enclosingScopeMergedSelectionBuilder must be provided for object type field.") | ||
} | ||
|
||
self = .entity( | ||
ASTField.EntityFieldData( | ||
type: field.type, | ||
selectionSet: selectionSet, | ||
enclosingEntityMergedSelectionBuilder: enclosingScopeMergedSelectionBuilder | ||
) | ||
) | ||
|
||
default: | ||
fatalError("Field \(field) must have a base type of scalar, enum, interface, union, or object. Got \(field.type.namedType)") | ||
} | ||
} | ||
} | ||
|
||
extension ASTField.EntityFieldData { | ||
static func == (lhs: ASTField.EntityFieldData, rhs: ASTField.EntityFieldData) -> Bool { | ||
lhs.selectionSet == rhs.selectionSet && | ||
lhs.enclosingEntityMergedSelectionBuilder === rhs.enclosingEntityMergedSelectionBuilder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.