Skip to content
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
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ public static async Task<ExecutionResult> ExecuteWithErrorCheck(
{
var executionResult = await executer.ExecuteAsync(options);

options.ThrowOnUnhandledException = true;
var errors = executionResult.Errors;
if (errors is { Count: > 0 })
{
Expand All @@ -629,7 +630,7 @@ public static async Task<ExecutionResult> ExecuteWithErrorCheck(
return executionResult;
}
```
<sup><a href='/src/GraphQL.EntityFramework/GraphQlExtensions.cs#L5-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-executewitherrorcheck' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/GraphQL.EntityFramework/GraphQlExtensions.cs#L5-L28' title='Snippet source file'>snippet source</a> | <a href='#snippet-executewitherrorcheck' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
26 changes: 11 additions & 15 deletions docs/defining-graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,9 @@ In some cases, it may be necessary to use `Field` instead of `AddQueryField`/`Ad
<!-- snippet: ManuallyApplyWhere -->
<a id='snippet-manuallyapplywhere'></a>
```cs
Field<ListGraphType<EmployeeSummaryGraphType>>(
name: "employeeSummary",
arguments: new(
new QueryArgument<ListGraphType<WhereExpressionGraph>>
{
Name = "where"
}
),
resolve: context =>
Field<ListGraphType<EmployeeSummaryGraphType>>("employeeSummary")
.Argument<ListGraphType<WhereExpressionGraph>>("where")
.Resolve(context =>
{
var dbContext = ResolveDbContext(context);
IQueryable<Employee> query = dbContext.Employees;
Expand All @@ -330,7 +324,10 @@ Field<ListGraphType<EmployeeSummaryGraphType>>(
}

return from q in query
group q by new {q.CompanyId}
group q by new
{
q.CompanyId
}
into g
select new EmployeeSummary
{
Expand All @@ -339,7 +336,7 @@ Field<ListGraphType<EmployeeSummaryGraphType>>(
};
});
```
<sup><a href='/src/SampleWeb/Query.cs#L53-L86' title='Snippet source file'>snippet source</a> | <a href='#snippet-manuallyapplywhere' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/SampleWeb/Query.cs#L53-L83' title='Snippet source file'>snippet source</a> | <a href='#snippet-manuallyapplywhere' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -355,17 +352,16 @@ public class Query :
{
public Query(IEfGraphQLService<MyDbContext> graphQlService) :
base(graphQlService) =>
Field<ListGraphType<CompanyGraph>>(
name: "oldCompanies",
resolve: context =>
Field<ListGraphType<CompanyGraph>>("oldCompanies")
.Resolve(context =>
{
// uses the base QueryGraphType to resolve the db context
var dbContext = ResolveDbContext(context);
return dbContext.Companies.Where(x => x.Age > 10);
});
}
```
<sup><a href='/src/Snippets/ResolveDbContextQuery.cs#L7-L24' title='Snippet source file'>snippet source</a> | <a href='#snippet-queryresolvedbcontext' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Snippets/ResolveDbContextQuery.cs#L7-L23' title='Snippet source file'>snippet source</a> | <a href='#snippet-queryresolvedbcontext' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;NU5104;CS1573</NoWarn>
<Version>17.1.0</Version>
<Version>18.0.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
<SignAssembly>false</SignAssembly>
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.EntityFramework/GraphQL.EntityFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.1" PrivateAssets="All" />
<PackageReference Include="Fody" Version="6.6.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="GraphQL" Version="5.3.3" />
<PackageReference Include="GraphQL" Version="7.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Include="NullabilityInfo" Version="1.0.7" PrivateAssets="all" />
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.EntityFramework/Mapping/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ static void AddMember<TSource>(ComplexGraphType<TSource> graph, PropertyInfo pro
{
var (compile, propertyGraphType) = Compile<TSource>(property);
var resolver = new SimpleFieldResolver<TSource>(compile);
var graphQlField = graph.Field(type: propertyGraphType, name: property.Name);
graphQlField.Resolver = resolver;
graph.Field(type: propertyGraphType, name: property.Name)
.Resolve(resolver);
}

static bool ShouldIgnore(IComplexGraphType graphType, string name, Type propertyType, IReadOnlyList<string>? localIgnores = null)
Expand Down
28 changes: 5 additions & 23 deletions src/GraphQL.EntityFramework/Where/Graphs/ArgumentGraphs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@

static class ArgumentGraphs
{
static Dictionary<Type, GraphType> entries = new();

[ModuleInitializer]
public static void Initialize()
{
Add<EnumerationGraphType<StringComparison>>();
Add<WhereExpressionGraph>();
Add<OrderByGraph>();
Add<ComparisonGraph>();
Add<ConnectorGraph>();
}

public static void RegisterInContainer(IServiceCollection services)
{
foreach (var entry in entries)
{
services.AddSingleton(entry.Key, entry.Value);
}
}

static void Add<T>()
where T : GraphType, new()
{
var value = new T();
entries.Add(typeof(T), value);
services.AddSingleton<EnumerationGraphType<StringComparison>>();
services.AddSingleton<WhereExpressionGraph>();
services.AddSingleton<OrderByGraph>();
services.AddSingleton<ComparisonGraph>();
services.AddSingleton<ConnectorGraph>();
}
}
12 changes: 7 additions & 5 deletions src/GraphQL.EntityFramework/Where/Graphs/WhereExpressionGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public WhereExpressionGraph()
{
Name = nameof(WhereExpression);
Field(x => x.Path, true);
Field<ComparisonGraph>("comparison", null, null, _ => _.Source.Comparison);
Field<ComparisonGraph>("comparison")
.Resolve(_ => _.Source.Comparison);
Field(x => x.Negate, true);
Field<EnumerationGraphType<StringComparison>>("case", null, null, _ => _.Source.Case);
Field<EnumerationGraphType<StringComparison>>("case")
.Resolve( _ => _.Source.Case);
Field(x => x.Value, true);
Field<ConnectorGraph>("connector", null, null, _ => _.Source.Connector);
Field<ListGraphType<WhereExpressionGraph>>(
name: "GroupedExpressions");
Field<ConnectorGraph>("connector")
.Resolve(_ => _.Source.Connector);
Field<ListGraphType<WhereExpressionGraph>>("GroupedExpressions");
}
}
2 changes: 1 addition & 1 deletion src/SampleWeb.Tests/SampleWeb.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphQL" Version="5.3.3" />
<PackageReference Include="GraphQL" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.8" />
<PackageReference Include="Xunit" Version="2.4.2" />
<PackageReference Include="Verify.Xunit" Version="17.10.2" />
Expand Down
17 changes: 7 additions & 10 deletions src/SampleWeb/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ public Query(IEfGraphQLService<SampleDbContext> efGraphQlService) :

#region ManuallyApplyWhere

Field<ListGraphType<EmployeeSummaryGraphType>>(
name: "employeeSummary",
arguments: new(
new QueryArgument<ListGraphType<WhereExpressionGraph>>
{
Name = "where"
}
),
resolve: context =>
Field<ListGraphType<EmployeeSummaryGraphType>>("employeeSummary")
.Argument<ListGraphType<WhereExpressionGraph>>("where")
.Resolve(context =>
{
var dbContext = ResolveDbContext(context);
IQueryable<Employee> query = dbContext.Employees;
Expand All @@ -74,7 +68,10 @@ public Query(IEfGraphQLService<SampleDbContext> efGraphQlService) :
}

return from q in query
group q by new {q.CompanyId}
group q by new
{
q.CompanyId
}
into g
select new EmployeeSummary
{
Expand Down
4 changes: 2 additions & 2 deletions src/SampleWeb/SampleWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Folder Include="wwwroot\" />
<PackageReference Include="EfLocalDb" Version="13.9.3" />
<PackageReference Include="graphiql" Version="2.0.0" />
<PackageReference Include="GraphQL.SystemTextJson" Version="5.3.3" />
<PackageReference Include="GraphQL" Version="5.3.3" />
<PackageReference Include="GraphQL.SystemTextJson" Version="7.0.1" />
<PackageReference Include="GraphQL" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
5 changes: 2 additions & 3 deletions src/Snippets/ResolveDbContextQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ public class Query :
{
public Query(IEfGraphQLService<MyDbContext> graphQlService) :
base(graphQlService) =>
Field<ListGraphType<CompanyGraph>>(
name: "oldCompanies",
resolve: context =>
Field<ListGraphType<CompanyGraph>>("oldCompanies")
.Resolve(context =>
{
// uses the base QueryGraphType to resolve the db context
var dbContext = ResolveDbContext(context);
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Snippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphQL" Version="5.3.3" />
<PackageReference Include="GraphQL" Version="7.0.1" />
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
<PackageReference Include="Xunit" Version="2.4.2" />
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<NoWarn>EF1000</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphQL" Version="5.3.3" />
<PackageReference Include="GraphQL.SystemTextJson" Version="5.3.3" />
<PackageReference Include="GraphQL" Version="7.0.1" />
<PackageReference Include="GraphQL.SystemTextJson" Version="7.0.1" />
<PackageReference Include="EfLocalDb" Version="13.9.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
<PackageReference Include="Verify.SqlServer" Version="3.4.2" />
Expand Down