graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

DataLoader Source Generator

Open michaelstaib opened this issue 3 years ago • 1 comments
trafficstars

[BatchDataLoader]
public static IQueryable<Asset> AssetById(
    IReadOnlyList<int> ids,
    [DbContext(DbContextKind.Scoped)] AssetContext context)
    => context.Assets.Where(t => ids.Contains(t.Id));

[DataLoader(DataLoaderKind.Group)]
public static IQueryable<Asset> AssetById(
    IReadOnlyList<int> ids,
    [DbContext(DbContextKind.Pooled)] AssetContext context,
    [Service(ServiceKind.Scoped)] Foo s)
    => context.Assets.Where(t => ids.Contains(t.Id));

[DataLoader]
public static IQueryable<Asset> AssetById(
    IReadOnlyList<int> ids,
    ISelection selection,
    IArgumentMap arguments,
    [DbContext(DbContextKind.Pooled)] AssetContext context)
    => context.Assets.Where(t => ids.Contains(t.Id)).Project(selection);

[BatchDataLoader]
public static IDictionary<int, Asset> AssetById(
    IReadOnlyList<int> ids,
    [DbContext(DbContextKind.Pooled)] AssetContext context,
    [Service(ServiceKind.Scoped)] Repo repo)
    => repo.GetItems(ids);

michaelstaib avatar Sep 08 '22 12:09 michaelstaib

This is very cool, @michaelstaib !

oising avatar Sep 19 '22 19:09 oising

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 17 '23 21:01 stale[bot]

StaleBot has great timing 😅 I think we can close this, as it landed yesterday...

tobias-tengler avatar Jan 17 '23 23:01 tobias-tengler

@tobias-tengler was the landing including IQueryable support?

Pjotrtje avatar Jan 25 '23 13:01 Pjotrtje

What do you mean by IQueryable support? But likely the answer is no. The change was just to simplify how you write DataLoader and give more control over the service scope being used. Nothing special like projection support or similar things was added...

tobias-tengler avatar Jan 25 '23 13:01 tobias-tengler

@tobias-tengler Ok, too bad. What I meant was that in original post Michael writes:

[DataLoader(DataLoaderKind.Group)]
public static IQueryable<Asset> AssetById(
    IReadOnlyList<int> ids,
    [DbContext(DbContextKind.Pooled)] AssetContext context,
    [Service(ServiceKind.Scoped)] Foo s)
    => context.Assets.Where(t => ids.Contains(t.Id));

[DataLoader]
public static IQueryable<Asset> AssetById(
    IReadOnlyList<int> ids,
    ISelection selection,
    IArgumentMap arguments,
    [DbContext(DbContextKind.Pooled)] AssetContext context)
    => context.Assets.Where(t => ids.Contains(t.Id)).Project(selection);

Which was the reason I heart-ed the openings post =). So when this was closed I was thrilled! But I guess this is not part of HC13?

Pjotrtje avatar Jan 25 '23 13:01 Pjotrtje

Not as far as I'm aware. Maybe you can write another issue that specifically requests this :)

tobias-tengler avatar Jan 25 '23 16:01 tobias-tengler