Skip to content
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

Added missing ParallelExecutable flag to node and nodes fields #7661

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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; }
}
}
Loading