Skip to content

Commit 8aea810

Browse files
committed
graphql: Simplify handling of one child per parent in prefetch::fetch
1 parent 0d8f976 commit 8aea810

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

graphql/src/store/prefetch.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fn execute_field(
803803
&parents,
804804
&join,
805805
argument_values,
806-
sast::is_list_or_non_null_list_field(field_definition),
806+
!sast::is_list_or_non_null_list_field(field_definition),
807807
ctx.query.schema.types_for_interface(),
808808
resolver.block,
809809
ctx.max_first,
@@ -812,28 +812,23 @@ fn execute_field(
812812
}
813813

814814
/// Query child entities for `parents` from the store. The `join` indicates
815-
/// in which child field to look for the parent's id/join field
815+
/// in which child field to look for the parent's id/join field. When
816+
/// `is_single` is `true`, there is at most one child per parent.
816817
fn fetch<S: Store>(
817818
logger: Logger,
818819
store: &S,
819820
parents: &Vec<Node>,
820821
join: &Join<'_>,
821822
mut arguments: HashMap<&q::Name, q::Value>,
822-
is_list: bool,
823+
is_single: bool,
823824
types_for_interface: &BTreeMap<s::Name, Vec<s::ObjectType>>,
824825
block: BlockNumber,
825826
max_first: u32,
826827
) -> Result<Vec<Node>, QueryExecutionError> {
827-
if !arguments.contains_key(&*ARG_FIRST) {
828-
let first = if is_list {
829-
// This makes `build_range` use the default, 100
830-
q::Value::Null
831-
} else {
832-
// For non-list fields, get up to 2 entries so we can spot
833-
// ambiguous references that should only have one entry
834-
q::Value::Int(2.into())
835-
};
836-
arguments.insert(&*ARG_FIRST, first);
828+
if is_single {
829+
// For non-list fields, get up to 2 entries so we can spot
830+
// ambiguous references that should only have one entry
831+
arguments.insert(&*ARG_FIRST, q::Value::Int(2.into()));
837832
}
838833

839834
if !arguments.contains_key(&*ARG_SKIP) {
@@ -849,7 +844,7 @@ fn fetch<S: Store>(
849844
max_first,
850845
)?;
851846

852-
if !is_list {
847+
if is_single {
853848
// Suppress 'order by' in lookups of scalar values since
854849
// that causes unnecessary work in the database
855850
query.order = EntityOrder::Unordered;

0 commit comments

Comments
 (0)