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

Rework AST to be more type safe and allow mutation #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
lukel97 wants to merge 19 commits into GraphQLSwift:main
base: main
Choose a base branch
Loading
from minm-inc:mutatable-visitor
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
876c29b
Rework AST to be more type safe and allow mutation
lukel97 Dec 21, 2021
75fb18f
Remove kinds as they are no longer needed
lukel97 Dec 22, 2021
f12c6ba
WIP
lukel97 Jan 26, 2022
13a95b0
Lazily reoslve interface's interfaces in BuildClientSchema
lukel97 Feb 22, 2022
6495218
Fix doTypesOverlap when seeing if object overlaps with interface
lukel97 Feb 23, 2022
ac2a4ed
Handle interface implementations of other interfaces
lukel97 Feb 23, 2022
ac9fbbc
Add variables are input types validation rule
lukel97 Feb 24, 2022
f1d3e38
Fix introspection query encoding
lukel97 Mar 23, 2022
8a71abf
Add specifiedByURL to scalar types
lukel97 Apr 20, 2022
0765b9f
Make subtyping reflexive
lukel97 Jun 9, 2022
3933850
Make GraphQLType Equatable
lukel97 Jun 9, 2022
edcfcba
Make GraphQLNamedType conform to Hashable
lukel97 Jun 9, 2022
fb0397c
Add KnownFragmentNamesRule validation rule
lukel97 Jun 10, 2022
215d0fa
Use ordered dictionary for GraphQLEnumValueMap
lukel97 Jul 21, 2022
de70703
Handle InputObjects in BuildClientSchema for introspection queries
lukel97 Jul 29, 2022
1e830cd
Make InputObjectFieldMap an ordered dictionary
lukel97 Jul 29, 2022
3a4e165
Make InputObject fields lazy
lukel97 Jul 29, 2022
d476ab0
Add tests for VariablesAreInputTypesRule
lukel97 Jul 29, 2022
a353056
Use OrderedDictionary throughout schema definitions
lukel97 Aug 1, 2022
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
4 changes: 2 additions & 2 deletions Package.resolved
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.library(name: "GraphQL", targets: ["GraphQL"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.10.1")),
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.38.0")),
.package(url: "https://github.com/apple/swift-collections", .upToNextMajor(from: "1.0.0")),
],
targets: [
Expand Down
54 changes: 25 additions & 29 deletions Sources/GraphQL/Execution/Execute.swift
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -359,23 +359,21 @@ func buildExecutionContext(

for definition in documentAST.definitions {
switch definition {
case let definition as OperationDefinition:
case .executableDefinition(.operation(let definition)):
guard !(operationName == nil && possibleOperation != nil) else {
throw GraphQLError(
message: "Must provide operation name if query contains multiple operations."
)
}

if operationName == nil || definition.name?.value == operationName {
possibleOperation = definition
}

case let definition as FragmentDefinition:
case .executableDefinition(.fragment(let definition)):
fragments[definition.name.value] = definition

default:
throw GraphQLError(
message: "GraphQL cannot execute a request containing a \(definition.kind).",
message: "GraphQL cannot execute a request containing a \(type(of: definition)).",
nodes: [definition]
)
}
Expand Down Expand Up @@ -502,7 +500,7 @@ func collectFields(

for selection in selectionSet.selections {
switch selection {
case let field as Field:
case .field(let field):
let shouldInclude = try shouldIncludeNode(
exeContext: exeContext,
directives: field.directives
Expand All @@ -519,7 +517,7 @@ func collectFields(
}

fields[name]?.append(field)
case let inlineFragment as InlineFragment:
case .inlineFragment(let inlineFragment):
let shouldInclude = try shouldIncludeNode(
exeContext: exeContext,
directives: inlineFragment.directives
Expand All @@ -542,43 +540,41 @@ func collectFields(
fields: &fields,
visitedFragmentNames: &visitedFragmentNames
)
case let fragmentSpread as FragmentSpread:
case .fragmentSpread(let fragmentSpread):
let fragmentName = fragmentSpread.name.value

let shouldInclude = try shouldIncludeNode(
exeContext: exeContext,
directives: fragmentSpread.directives
)

guard visitedFragmentNames[fragmentName] == nil && shouldInclude else {
continue
}

visitedFragmentNames[fragmentName] = true

guard let fragment = exeContext.fragments[fragmentName] else {
continue
}

let fragmentConditionMatches = try doesFragmentConditionMatch(
exeContext: exeContext,
fragment: fragment,
type: runtimeType
)

guard fragmentConditionMatches else {
continue
}

try collectFields(
exeContext: exeContext,
runtimeType: runtimeType,
selectionSet: fragment.selectionSet,
fields: &fields,
visitedFragmentNames: &visitedFragmentNames
)
default:
break
}
}

Expand Down Expand Up @@ -629,15 +625,15 @@ func doesFragmentConditionMatch(
return true
}

guard let conditionalType = typeFromAST(schema: exeContext.schema, inputTypeAST: typeConditionAST) else {
guard let conditionalType = typeFromAST(schema: exeContext.schema, inputTypeAST: .namedType(typeConditionAST)) else {
return true
}

if let conditionalType = conditionalType as? GraphQLObjectType, conditionalType.name == type.name {
return true
}

if let abstractType = conditionalType as? GraphQLAbstractType {
if let abstractType = conditionalType as? (any GraphQLAbstractType) {
return exeContext.schema.isSubType(
abstractType: abstractType,
maybeSubType: type
Expand Down Expand Up @@ -765,7 +761,7 @@ func resolveOrError(
// in the execution context.
func completeValueCatchingError(
exeContext: ExecutionContext,
returnType: GraphQLType,
returnType: any GraphQLType,
fieldASTs: [Field],
info: GraphQLResolveInfo,
path: IndexPath,
Expand Down Expand Up @@ -817,7 +813,7 @@ func completeValueCatchingError(
// location information.
func completeValueWithLocatedError(
exeContext: ExecutionContext,
returnType: GraphQLType,
returnType: any GraphQLType,
fieldASTs: [Field],
info: GraphQLResolveInfo,
path: IndexPath,
Expand Down Expand Up @@ -867,7 +863,7 @@ func completeValueWithLocatedError(
*/
func completeValue(
exeContext: ExecutionContext,
returnType: GraphQLType,
returnType: any GraphQLType,
fieldASTs: [Field],
info: GraphQLResolveInfo,
path: IndexPath,
Expand Down Expand Up @@ -916,13 +912,13 @@ func completeValue(

// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
// returning .null if serialization is not possible.
if let returnType = returnType as? GraphQLLeafType {
if let returnType = returnType as? any GraphQLLeafType {
return exeContext.eventLoopGroup.next().makeSucceededFuture(try completeLeafValue(returnType: returnType, result: r))
}

// If field type is an abstract type, Interface or Union, determine the
// runtime Object type and complete for that type.
if let returnType = returnType as? GraphQLAbstractType {
if let returnType = returnType as? any GraphQLAbstractType {
return try completeAbstractValue(
exeContext: exeContext,
returnType: returnType,
Expand Down Expand Up @@ -999,7 +995,7 @@ func completeListValue(
* Complete a Scalar or Enum by serializing to a valid value, returning
* .null if serialization is not possible.
*/
func completeLeafValue(returnType: GraphQLLeafType, result: Any?) throws -> Map {
func completeLeafValue(returnType: any GraphQLLeafType, result: Any?) throws -> Map {
guard let result = result else {
return .null
}
Expand All @@ -1023,7 +1019,7 @@ func completeLeafValue(returnType: GraphQLLeafType, result: Any?) throws -> Map
*/
func completeAbstractValue(
exeContext: ExecutionContext,
returnType: GraphQLAbstractType,
returnType: any GraphQLAbstractType,
fieldASTs: [Field],
info: GraphQLResolveInfo,
path: IndexPath,
Expand All @@ -1046,7 +1042,7 @@ func completeAbstractValue(
}

// If resolveType returns a string, we assume it's a GraphQLObjectType name.
var runtimeType: GraphQLType?
var runtimeType: (any GraphQLType)?

switch resolveResult {
case .name(let name):
Expand Down Expand Up @@ -1143,7 +1139,7 @@ func defaultResolveType(
value: Any,
eventLoopGroup: EventLoopGroup,
info: GraphQLResolveInfo,
abstractType: GraphQLAbstractType
abstractType: any GraphQLAbstractType
) throws -> TypeResolveResult? {
let possibleTypes = info.schema.getPossibleTypes(abstractType: abstractType)

Expand Down
10 changes: 5 additions & 5 deletions Sources/GraphQL/Execution/Values.swift
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func getVariableValue(schema: GraphQLSchema, definitionAST: VariableDefinition,
let type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type)
let variable = definitionAST.variable

guard let inputType = type as? GraphQLInputType else {
guard let inputType = type as? (any GraphQLInputType) else {
throw GraphQLError(
message:
"Variable \"$\(variable.name.value)\" expected value of type " +
Expand Down Expand Up @@ -112,11 +112,11 @@ func getVariableValue(schema: GraphQLSchema, definitionAST: VariableDefinition,
/**
* Given a type and any value, return a runtime value coerced to match the type.
*/
func coerceValue(value: Map, type: GraphQLInputType) throws -> Map {
func coerceValue(value: Map, type: any GraphQLInputType) throws -> Map {
if let nonNull = type as? GraphQLNonNull {
// Note: we're not checking that the result of coerceValue is non-null.
// We only call this function after calling validate.
guard let nonNullType = nonNull.ofType as? GraphQLInputType else {
guard let nonNullType = nonNull.ofType as? (any GraphQLInputType) else {
throw GraphQLError(message: "NonNull must wrap an input type")
}
return try coerceValue(value: value, type: nonNullType)
Expand All @@ -127,7 +127,7 @@ func coerceValue(value: Map, type: GraphQLInputType) throws -> Map {
}

if let list = type as? GraphQLList {
guard let itemType = list.ofType as? GraphQLInputType else {
guard let itemType = list.ofType as? (any GraphQLInputType) else {
throw GraphQLError(message: "Input list must wrap an input type")
}

Expand Down Expand Up @@ -168,7 +168,7 @@ func coerceValue(value: Map, type: GraphQLInputType) throws -> Map {
return .dictionary(object)
}

if let leafType = type as? GraphQLLeafType {
if let leafType = type as? (any GraphQLLeafType) {
return try leafType.parseValue(value: value)
}

Expand Down
Loading

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