Skip to content

Commit

Permalink
Update to GraphQL Version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Ganhammar committed Mar 20, 2021
1 parent 0f9d8d9 commit 4d52af2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 45 deletions.
14 changes: 7 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

<PropertyGroup>
<CoverletMsbuildVersion>3.0.3</CoverletMsbuildVersion>
<GraphQLVersion>3.2.0</GraphQLVersion>
<GraphQLServerVersion>4.4.0</GraphQLServerVersion>
<MicrosoftNetTestSdkVersion>16.8.3</MicrosoftNetTestSdkVersion>
<GraphQLVersion>4.0.2</GraphQLVersion>
<GraphQLServerVersion>5.0.0</GraphQLServerVersion>
<MicrosoftNetTestSdkVersion>16.9.1</MicrosoftNetTestSdkVersion>
<ShouldlyVersion>4.0.3</ShouldlyVersion>
<XunitVersion>2.4.1</XunitVersion>
<XunitRunnerVisualstudioVersion>2.4.3</XunitRunnerVisualstudioVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(IsNetCore5OnwardsTarget)' == 'False'">
<MicrosoftAspNetCoreMvcTestingVersion>3.1.10</MicrosoftAspNetCoreMvcTestingVersion>
<MicrosoftEntityFrameworkCoreVersion>3.1.10</MicrosoftEntityFrameworkCoreVersion>
<MicrosoftAspNetCoreMvcTestingVersion>3.1.13</MicrosoftAspNetCoreMvcTestingVersion>
<MicrosoftEntityFrameworkCoreVersion>3.1.13</MicrosoftEntityFrameworkCoreVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(IsNetCore5OnwardsTarget)' == 'True'">
<MicrosoftAspNetCoreMvcTestingVersion>5.0.1</MicrosoftAspNetCoreMvcTestingVersion>
<MicrosoftEntityFrameworkCoreVersion>5.0.1</MicrosoftEntityFrameworkCoreVersion>
<MicrosoftAspNetCoreMvcTestingVersion>5.0.4</MicrosoftAspNetCoreMvcTestingVersion>
<MicrosoftEntityFrameworkCoreVersion>5.0.4</MicrosoftEntityFrameworkCoreVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ public static class FieldBuilderExtensions
return queryBuilder;
}

public static FieldQueryBuilder<TSourceType, TReturnType, TProperty> From<TSourceType, TReturnType, TDbContext, TProperty>(
this FieldBuilder<TSourceType, TReturnType> builder,
TDbContext _,
Expression<Func<TDbContext, DbSet<TProperty>>> accessor)
where TDbContext : DbContext
where TProperty : class
{
var targetType = FieldHelpers.GetPropertyInfo(accessor).PropertyType
.GetGenericArguments().First();
var queryBuilder = new FieldQueryBuilder<TSourceType, TReturnType, TProperty>(builder, targetType, typeof(TDbContext));

return queryBuilder;
}

public static FieldQueryBuilder<TSourceType, object, TProperty> From<TSourceType, TProperty>(
this FieldBuilder<TSourceType, object> builder,
DbSet<TProperty> property)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using GraphQL.Utilities;
using Microsoft.Extensions.DependencyInjection;

namespace GraphQL.EntityFrameworkCore.Helpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static FilterableInput GetFilter(IResolveFieldContext<object> context)
return default;
}

var fields = GetOperationBranch(context.Operation.SelectionSet, context.FieldName);
var fields = GetOperationBranch(context.Operation.SelectionSet, context.FieldDefinition.Name);

foreach (Field field in fields)
{
Expand All @@ -61,7 +61,7 @@ public static FilterableInput GetFilter(IResolveFieldContext<object> context)
var filterInputReference = (VariableReference)filter.Children.First(x => x.GetType() == typeof(VariableReference));
var input = GetFilterableInput(filterInputReference.Name, context);

if (context.FieldName == field.Name || input.Mode == FilterableModes.Deep)
if (context.FieldDefinition.Name == field.Name || input.Mode == FilterableModes.Deep)
{
return input;
}
Expand All @@ -74,9 +74,8 @@ public static FilterableInput GetFilter(IResolveFieldContext<object> context)
private static FilterableInput GetFilterableInput(string inputName, IResolveFieldContext<object> context)
{
var variable = context.Variables.First(x => x.Name == inputName);
var arguments = variable.Value as IDictionary<string, object>;

return (FilterableInput)arguments.ToObject(typeof(FilterableInput));
return (FilterableInput)variable.Value;
}

private static List<Field> GetOperationBranch(SelectionSet operation, string target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<Authors>Anton Ganhammar</Authors>
<Company />
<RepositoryUrl>https://github.com/ganhammar/GraphQL.EntityFrameworkCore.Helpers</RepositoryUrl>
Expand All @@ -14,6 +14,7 @@

<ItemGroup>
<PackageReference Include="GraphQL" Version="$(GraphQLVersion)" />
<PackageReference Include="GraphQL.DataLoader" Version="$(GraphQLVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(MicrosoftEntityFrameworkCoreVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Linq;
using System.Threading.Tasks;
using GraphQL.EntityFrameworkCore.Helpers.Tests.Infrastructure;
using GraphQL.Utilities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GraphQL.SystemTextJson;

namespace GraphQL.EntityFrameworkCore.Helpers.Tests.Infrastructure
{
public static class JsonStringExtensions
{
public static ExecutionResult ToExecutionResult(this string json, ExecutionErrors errors = null, bool executed = true)
=> new ExecutionResult
{
Data = string.IsNullOrWhiteSpace(json) ? null : json.ToDictionary(),
Errors = errors,
Executed = executed
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public IServiceProvider GetServiceProvider()
services
.AddGraphQLEntityFrameworkCoreHelpers<TestDbContext>()
.AddSingleton<IDocumentExecutionListener, DataLoaderDocumentListener>()
.AddSingleton<INameConverter, CamelCaseNameConverter>()
.AddSingleton<ISchema, TestSchema>()
.AddTransient<PlanetGraphType>()
.AddTransient<HumanGraphType>()
Expand Down Expand Up @@ -178,7 +179,6 @@ public IServiceProvider GetServiceProvider()
x.UserContext = userContext;
x.CancellationToken = cancellationToken;
x.ValidationRules = rules;
x.NameConverter = new CamelCaseNameConverter();
x.RequestServices = ServiceProvider;
foreach (var listener in ServiceProvider.GetService<IEnumerable<IDocumentExecutionListener>>())
{
Expand All @@ -204,11 +204,7 @@ public IServiceProvider GetServiceProvider()
}

public static ExecutionResult CreateQueryResult(string result, ExecutionErrors errors = null)
=> new ExecutionResult
{
Data = string.IsNullOrWhiteSpace(result) ? null : result.ToDictionary(),
Errors = errors
};
=> result.ToExecutionResult(errors);

protected static IResolveFieldContext<object> GetContext(string queryName = "humans", string filter = default, string[] fields = default)
{
Expand All @@ -226,10 +222,12 @@ protected static IResolveFieldContext<object> GetContext(string queryName = "hum
context.SubFields.Add(fieldName, new Field(new NameNode(fieldName), new NameNode(fieldName)));
}

context.FieldName = queryName;
context.FieldDefinition = new FieldType();

context.FieldDefinition.Name = queryName;
context.Path = new List<string> { queryName };

var field = new Field(new NameNode(context.FieldName), new NameNode(context.FieldName));
var field = new Field(new NameNode(context.FieldDefinition.Name), new NameNode(context.FieldDefinition.Name));
field.SelectionSet = new SelectionSet();

foreach(var fieldName in fields)
Expand All @@ -240,13 +238,12 @@ protected static IResolveFieldContext<object> GetContext(string queryName = "hum
if (filter != default)
{
field.Arguments = new Arguments();
field.Arguments.Add(new Argument(new NameNode("filter"))
{
Value = new VariableReference(new NameNode("filter")),
});
field.Arguments.Add(new Argument(
new NameNode("filter"),
new VariableReference(new NameNode("filter"))));
}

context.Operation = new Operation(new NameNode(context.FieldName));
context.Operation = new Operation(new NameNode(context.FieldDefinition.Name));
context.Operation.SelectionSet = new SelectionSet();
context.Operation.SelectionSet.Add(field);

Expand All @@ -255,11 +252,18 @@ protected static IResolveFieldContext<object> GetContext(string queryName = "hum
return context;
}

var fieldsInput = new Dictionary<string, object>();
fieldsInput.Add("value", filter);
var fieldsInput = new List<FilterableInputField>
{
new FilterableInputField
{
Value = filter,
},
};

var filterInput = new Dictionary<string, object>();
filterInput.Add("fields", new List<Dictionary<string, object>> { fieldsInput });
var filterInput = new FilterableInput
{
Fields = fieldsInput,
};

context.Variables = new Variables();
context.Variables.Add(new Variable
Expand Down

0 comments on commit 4d52af2

Please sign in to comment.