-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Optimize fragment validation #2039
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,20 +64,26 @@ object Executor { | |
): ReducedStep[R] = { | ||
|
||
def reduceObjectStep(objectName: String, getFieldStep: String => Step[R]): ReducedStep[R] = { | ||
def reduceField(f: Field): (String, ReducedStep[R], FieldInfo) = { | ||
val field = | ||
if (f.name == "__typename") PureStep(StringValue(objectName)) | ||
else reduceStep(getFieldStep(f.name), f, f.arguments, Left(f.aliasedName) :: path) | ||
(f.aliasedName, field, fieldInfo(f, path, f.directives)) | ||
} | ||
|
||
val filteredFields = mergeFields(currentField, objectName) | ||
val (deferred, eager) = filteredFields.partitionMap { | ||
case f @ Field("__typename", _, _, _, _, _, _, directives, _, _, _) => | ||
Right((f.aliasedName, PureStep(StringValue(objectName)), fieldInfo(f, path, directives))) | ||
case f @ Field(name, _, _, _, _, _, args, directives, _, _, fragment) => | ||
val field = reduceStep(getFieldStep(name), f, args, Left(f.aliasedName) :: path) | ||
val entry = (f.aliasedName, field, fieldInfo(f, path, directives)) | ||
|
||
fragment match { | ||
// The defer spec provides some latitude on how we handle responses. Since it is more performant to return | ||
// pure fields rather than spin up the defer machinery we return pure fields immediately to the caller. | ||
case Some(IsDeferred(label)) if isDeferredEnabled && !field.isPure => Left((label, entry)) | ||
case _ => Right(entry) | ||
val (deferred, eager) = { | ||
if (isDeferredEnabled) { | ||
filteredFields.partitionMap { f => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That one's pretty good! I ran the profiler a whole ago and I remember this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah besides avoiding wrapping the steps into an Either, |
||
val entry = reduceField(f) | ||
f.fragment match { | ||
// The defer spec provides some latitude on how we handle responses. Since it is more performant to return | ||
// pure fields rather than spin up the defer machinery we return pure fields immediately to the caller. | ||
case Some(IsDeferred(label)) if !entry._2.isPure => Left((label, entry)) | ||
case _ => Right(entry) | ||
} | ||
} | ||
} else (Nil, filteredFields.map(reduceField)) | ||
} | ||
|
||
val eagerReduced = reduceObject(eager, wrapPureValues) | ||
|
@@ -303,7 +309,7 @@ object Executor { | |
|
||
for { | ||
cache <- Cache.empty | ||
reduced = reduceStep(plan, request.field, Map(), Nil) | ||
reduced = reduceStep(plan, request.field, Map.empty, Nil) | ||
response <- runQuery(reduced, cache) | ||
} yield response | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: I disabled this since I had to add too many filters due to the removed methods