Skip to content
Draft
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
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GreenDonut;
using HotChocolate.DataLoader;
using Metabase.GraphQl.DataX;

namespace Metabase.GraphQl.DataFormat
{
internal sealed class AllOpticalDataByDataFormatDataLoader
: BatchDataLoader<(Data.DataFormat DataFormat, OpticalDataPropositionInput Where, DateTime? Timestamp, string? Locale, uint? First, string? After, uint? Last, string? Before), OpticalDataConnection>
{
private readonly IDbContextFactory<Data.ApplicationDbContext> _dbContextFactory;

public AllOpticalDataByDataFormatDataLoader(
IBatchScheduler batchScheduler,
IDbContextFactory<Data.ApplicationDbContext> dbContextFactory
)
: base(batchScheduler)
{
_dbContextFactory = dbContextFactory;
}

protected override
Task<IReadOnlyDictionary<(Data.DataFormat DataFormat, OpticalDataPropositionInput Where, DateTime? Timestamp, string? Locale, uint? First, string? After, uint? Last, string? Before), OpticalDataConnection>>
LoadBatchAsync(
IReadOnlyList<(Data.DataFormat DataFormat, OpticalDataPropositionInput Where, DateTime? Timestamp, string? Locale, uint? First, string? After, uint? Last, string? Before)> keys,
CancellationToken cancellationToken
)
{
await using var dbContext =
_dbContextFactory.CreateDbContext();
return await _getQueryable(dbContext).AsQueryable()
.Where(entity => ids.Contains(entity.Id))
.ToDictionaryAsync(
entity => entity.Id,
entity => (TEntity?)entity,
cancellationToken
)
.ConfigureAwait(false);
keys
.GroupBy(key => (key.Where, key.Timestamp, key.Locale, key.First, key.After, key.Last, key.Before))
.;
}
}
}
48 changes: 48 additions & 0 deletions backend/src/GraphQl/DataFormat/DataFormatResolvers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Metabase.GraphQl.DataFormats
{
public sealed class DataFormatResolvers
{
public async Task<DataX.OpticalData?> GetOpticalDataAsync(
Data.Database database,
Guid id,
DateTime? timestamp,
string? locale,
CancellationToken cancellationToken
)
{
return null;
}

public async Task<DataX.OpticalDataConnection?> GetAllOpticalDataAsync(
Data.Database database,
DataX.OpticalDataPropositionInput where,
DateTime? timestamp,
string? locale,
uint? first,
string? after,
uint? last,
string? before,
AllOpticalDataDataLoader dataLoader,
CancellationToken cancellationToken
)
{
return dataLoader.LoadAsync(cancellationToken);
}

public async Task<bool?> GetHasOpticalDataAsync(
Data.Database database,
DataX.DataPropositionInput where,
DateTime? timestamp,
string? locale,
CancellationToken cancellationToken
)
{
return null;
}
}
}
16 changes: 16 additions & 0 deletions backend/src/GraphQl/DataFormat/DataFormatType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HotChocolate.Types;
using Metabase.GraphQl.DataX;

namespace Metabase.GraphQl.DataFormats
{
Expand Down Expand Up @@ -27,6 +28,21 @@ protected override void Configure(
descriptor
.Field(t => t.ManagerId)
.Ignore();
DataFieldConfigurator.ConfigureDataField<Data.DataFormat, DataFormatResolvers>(
descriptor,
"opticalData",
_ => _.GetOpticalDataAsync(default!, default!, default!, default!, default!)
);
DataFieldConfigurator.ConfigureAllDataField<Data.DataFormat, DataFormatResolvers, OpticalDataPropositionInput>(
descriptor,
"allOpticalData",
_ => _.GetAllOpticalDataAsync(default!, default!, default!, default!, default!, default!, default!, default!, default!)
);
DataFieldConfigurator.ConfigureHasDataField<Data.DataFormat, DataFormatResolvers, OpticalDataPropositionInput>(
descriptor,
"hasOpticalData",
_ => _.GetHasOpticalDataAsync(default!, default!, default!, default!, default!)
);
}
}
}
55 changes: 55 additions & 0 deletions backend/src/GraphQl/DataX/DataFieldConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Linq.Expressions;
using HotChocolate.Types;

namespace Metabase.GraphQl.DataX
{
internal static class DataFieldConfigurator
{
internal static void ConfigureDataField<TData, TResolvers>(
IObjectTypeDescriptor<TData> descriptor,
string fieldName,
Expression<Func<TResolvers, object?>> resolverMethod
)
{
descriptor
.Field(fieldName)
.Argument("id", _ => _.Type<NonNullType<UuidType>>())
.Argument("timestamp", _ => _.Type<DateTimeType>())
.Argument("locale", _ => _.Type<StringType>())
.ResolveWith(resolverMethod);
}

internal static void ConfigureAllDataField<TData, TResolvers, TDataPropositionInput>(
IObjectTypeDescriptor<TData> descriptor,
string fieldName,
Expression<Func<TResolvers, object?>> resolverMethod
)
{
descriptor
.Field(fieldName)
.Argument("where", _ => _.Type<NonNullType<InputObjectType<TDataPropositionInput>>>())
.Argument("timestamp", _ => _.Type<DateTimeType>())
.Argument("locale", _ => _.Type<StringType>())
.Argument("first", _ => _.Type<NonNegativeIntType>())
.Argument("after", _ => _.Type<StringType>())
.Argument("last", _ => _.Type<NonNegativeIntType>())
.Argument("before", _ => _.Type<StringType>())
.ResolveWith(resolverMethod);
}

internal static void ConfigureHasDataField<TData, TResolvers, TDataPropositionInput>(
IObjectTypeDescriptor<TData> descriptor,
string fieldName,
Expression<Func<TResolvers, object?>> resolverMethod
)
{
descriptor
.Field(fieldName)
.Argument("where", _ => _.Type<NonNullType<InputObjectType<TDataPropositionInput>>>())
.Argument("timestamp", _ => _.Type<DateTimeType>())
.Argument("locale", _ => _.Type<StringType>())
.ResolveWith(resolverMethod);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using GreenDonut;
using HotChocolate.DataLoader;
using Microsoft.EntityFrameworkCore;

namespace Metabase.GraphQl.Database
{
internal sealed class AllOpticalDataByDatabaseDataLoader
: BatchDataLoader<(Data.Database database, DataX.OpticalDataPropositionInput where, DateTime? timestamp, string? locale, uint? first, string? after, uint? last, string? before), OpticalDataConnection>
{
private readonly IDbContextFactory<Data.ApplicationDbContext> _dbContextFactory;

public AllOpticalDataByDatabaseDataLoader(
IBatchScheduler batchScheduler,
IDbContextFactory<Data.ApplicationDbContext> dbContextFactory
)
: base(batchScheduler)
{
_dbContextFactory = dbContextFactory;
}

protected override
Task<IReadOnlyDictionary<(Data.Database database, DataX.OpticalDataPropositionInput where, DateTime? timestamp, string? locale, uint? first, string? after, uint? last, string? before), OpticalDataConnection>>
LoadBatchAsync(
IReadOnlyList<(Data.Database database, DataX.OpticalDataPropositionInput where, DateTime? timestamp, string? locale, uint? first, string? after, uint? last, string? before)> keys,
CancellationToken cancellationToken
)
{
return (await QueryDatabase<AllOpticalDataData>(
database,
new GraphQL.GraphQLRequest(
query: await ConstructQuery(
new[] {
"DataFields.graphql",
"OpticalDataFields.graphql",
"PageInfoFields.graphql",
"AllOpticalData.graphql"
}
).ConfigureAwait(false),
variables: new
{
where,
timestamp,
locale,
first,
after,
last,
before
},
operationName: "AllOpticalData"
),
cancellationToken
).ConfigureAwait(false)
)?.AllOpticalData;
}
}
}