Skip to content

Commit

Permalink
Added missing ParallelExecutable flag to node and nodes fields (#7661)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Oct 31, 2024
1 parent 58b0888 commit f122129
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void CreateNodeField(
};
}),
},
Flags = FieldFlags.GlobalIdNodeField
Flags = FieldFlags.ParallelExecutable | FieldFlags.GlobalIdNodeField
};

// In the projection interceptor we want to change the context data that is on this field
Expand Down Expand Up @@ -134,7 +134,7 @@ private static void CreateNodesField(
};
}),
},
Flags = FieldFlags.GlobalIdNodesField
Flags = FieldFlags.ParallelExecutable | FieldFlags.GlobalIdNodesField
};

// In the projection interceptor we want to change the context data that is on this field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,43 @@ await ExpectValid(
await snapshot.MatchMarkdownAsync();
}

[Fact]
public async Task FetchMultipleNodesDataLoader()
{
var batchFetchCount = 0;

await ExpectValid(
"""
{
a: node(id: "RW50aXR5OjE==") { ... on Entity { id } }
b: node(id: "RW50aXR5OjI==") { ... on Entity { id } }
}
""",
configure: b => b
.AddGraphQL()
.AddGlobalObjectIdentification()
.AddObjectType<Entity>(descriptor =>
{
descriptor
.ImplementsNode()
.IdField(e => e.Id)
.ResolveNode(
async (ctx, id) => await ctx.BatchDataLoader<int, Entity>(
(keys, _) =>
{
batchFetchCount++;

return Task.FromResult<IReadOnlyDictionary<int, Entity>>(
keys.ToDictionary(t => t, _ => new Entity { Id = id }));
})
.LoadAsync(id))
.Resolve(ctx => ctx.Parent<Entity>().Id);
})
.AddQueryType());

Assert.Equal(1, batchFetchCount);
}

[LocalFact]
public async Task FetchDataLoader()
{
Expand Down Expand Up @@ -667,4 +704,9 @@ public CounterDataLoader(DataLoaderOptions options) : base(options)
protected override Task<string> LoadSingleAsync(string key, CancellationToken cancellationToken)
=> Task.FromResult(key + Counter);
}

public class Entity
{
public int Id { get; set; }
}
}

0 comments on commit f122129

Please sign in to comment.