Skip to content

Commit

Permalink
Add missing non-generic dataloader configration extensions (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
drowhunter authored and michaelstaib committed Dec 5, 2018
1 parent 91e3924 commit 70ca8ef
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 23 deletions.
80 changes: 62 additions & 18 deletions src/Core/DataLoaderConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ public static void RegisterDataLoader<TLoader>(
Func<IServiceProvider, TLoader> loaderFactory)
where TLoader : IDispatchableDataLoader
{
configuration.RegisterDataLoader<TLoader>(
key, scope, loaderFactory,
(d, c) => d.DispatchAsync());
configuration.RegisterDataLoader<TLoader>(key, scope, loaderFactory,(d, c) => d.DispatchAsync());
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration,
Type type,
string key,
ExecutionScope scope,
Func<IServiceProvider, IDispatchableDataLoader> loaderFactory)

{
configuration.RegisterDataLoader(type,key, scope, loaderFactory,(d, c) => ((IDispatchableDataLoader)d).DispatchAsync());
}

public static void RegisterDataLoader<TLoader>(
Expand All @@ -24,19 +33,33 @@ public static void RegisterDataLoader<TLoader>(
Func<IServiceProvider, TLoader> loaderFactory)
where TLoader : IDispatchableDataLoader
{
RegisterDataLoader<TLoader>(
configuration, typeof(TLoader).FullName,
scope, loaderFactory);
RegisterDataLoader<TLoader>(configuration, typeof(TLoader).FullName,scope, loaderFactory);
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration,
Type type,
ExecutionScope scope,
Func<IServiceProvider, IDispatchableDataLoader> loaderFactory)
{
RegisterDataLoader(configuration, type, type.FullName, scope, loaderFactory);
}

public static void RegisterDataLoader<TLoader>(
this ISchemaConfiguration configuration,
Func<IServiceProvider, TLoader> loaderFactory)
where TLoader : IDispatchableDataLoader
{
RegisterDataLoader<TLoader>(
configuration, typeof(TLoader).FullName,
ExecutionScope.Request, loaderFactory);
RegisterDataLoader<TLoader>(configuration, typeof(TLoader).FullName,ExecutionScope.Request, loaderFactory);
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration,
Type type,
Func<IServiceProvider, IDispatchableDataLoader> loaderFactory)

{
RegisterDataLoader(configuration, type,type.FullName,ExecutionScope.Request, loaderFactory);
}

public static void RegisterDataLoader<TLoader>(
Expand All @@ -45,28 +68,49 @@ public static void RegisterDataLoader<TLoader>(
ExecutionScope scope)
where TLoader : class, IDispatchableDataLoader
{
configuration.RegisterDataLoader<TLoader>(
key, scope, triggerLoaderAsync:
(d, c) => d.DispatchAsync());
configuration.RegisterDataLoader<TLoader>(key, scope, triggerLoaderAsync:(d, c) => d.DispatchAsync());
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration,
Type type,
string key,
ExecutionScope scope)

{
configuration.RegisterDataLoader(type,key, scope, triggerLoaderAsync:(d, c) => ((IDispatchableDataLoader)d).DispatchAsync());
}

public static void RegisterDataLoader<TLoader>(
this ISchemaConfiguration configuration,
ExecutionScope scope)
where TLoader : class, IDispatchableDataLoader
{
RegisterDataLoader<TLoader>(
configuration, typeof(TLoader).FullName,
scope);
RegisterDataLoader<TLoader>(configuration, typeof(TLoader).FullName,scope);
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration,
Type type,
ExecutionScope scope)

{
RegisterDataLoader(configuration, type, type.FullName,scope);
}

public static void RegisterDataLoader<TLoader>(
this ISchemaConfiguration configuration)
where TLoader : class, IDispatchableDataLoader
{
RegisterDataLoader<TLoader>(
configuration, typeof(TLoader).FullName,
ExecutionScope.Request);

RegisterDataLoader<TLoader>(configuration, typeof(TLoader).FullName,ExecutionScope.Request);
}

public static void RegisterDataLoader(
this ISchemaConfiguration configuration, Type type)

{
RegisterDataLoader(configuration,type, type.FullName,ExecutionScope.Request);
}
}
}
10 changes: 5 additions & 5 deletions src/Types/Configuration/SchemaConfiguration.DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public void RegisterDataLoader<T>(
Func<T, CancellationToken, Task> triggerLoaderAsync = null)
{

Func<IServiceProvider,object> f = null;
Func<IServiceProvider,object> factory = null;
if(loaderFactory != null)
f = s => loaderFactory(s);
Func<object,CancellationToken,Task> g = null;
factory = s => loaderFactory(s);
Func<object,CancellationToken,Task> trigger = null;
if(triggerLoaderAsync != null)
g = (a,b) => triggerLoaderAsync((T)a,b);
trigger = (a,b) => triggerLoaderAsync((T)a,b);

RegisterDataLoader(typeof(T),key,scope,f,g);
RegisterDataLoader(typeof(T),key,scope,factory,trigger);

}
}
Expand Down

0 comments on commit 70ca8ef

Please sign in to comment.