Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to GraphQL 4.5.0 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion GraphQL.SchemaDeclare.Tests/Fixtures/ServiceProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraphQL.SchemaDeclare.GenerationServices;
using GraphQL.Types;

namespace GraphQL.SchemaDeclare.Tests.Fixtures
{
public class ServiceProviderFixture
{
public ServiceProvider ServiceProvider { get; private set; }

public ServiceProviderFixture()
{
var clrToGraphTypeMappings = new ClrToGraphTypeMappings();
var schema = new EmptySchema();
IEnumerable<(Type clrType, Type graphType)> typeMappings = schema.BuiltInTypeMappings;

foreach (var (clrType, graphType) in typeMappings)
{
if (!clrToGraphTypeMappings.ContainsKey(clrType))
{
clrToGraphTypeMappings.Add(clrType, graphType);
}
}

var serviceCollection = new ServiceCollection();
serviceCollection.AddGraphQLSchemaDeclareService();
serviceCollection.AddGraphQLSchemaDeclareService(null, () => clrToGraphTypeMappings);
ServiceProvider = serviceCollection.BuildServiceProvider();

}
}

public class EmptySchema : Schema { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="3.0.0" />
<PackageReference Include="GraphQL" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
39 changes: 20 additions & 19 deletions GraphQL.SchemaDeclare.Tests/SchemaGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GraphQL.Execution;
using Xunit;

namespace GraphQL.SchemaDeclare.Tests
Expand Down Expand Up @@ -42,13 +43,13 @@ public TestQuery()
}
}

public class TestSchema : Schema
{
public TestSchema()
{
Query = new TestQuery();
}
}
public class TestSchema : Schema
{
public TestSchema()
{
Query = new TestQuery();
}
}

public class SchemaGenerationTests
{
Expand All @@ -59,7 +60,7 @@ public void WhenDeclaringQueryThenGenerationIsAsExpected()

schema.Initialize();

var type = schema.FindType("TestQuery") as ObjectGraphType<object>;
var type = schema.AllTypes["TestQuery"] as ObjectGraphType<object>;

Assert.NotNull(type);
Assert.NotEmpty(type.Fields);
Expand All @@ -70,9 +71,9 @@ public void WhenDeclaringQueryThenGenerationIsAsExpected()
var test = 5;
var result = field.Resolver.Resolve(new ResolveFieldContext()
{
Arguments = new Dictionary<string, object>()
Arguments = new Dictionary<string, ArgumentValue>()
{
{ "test", test }
{ "test", new ArgumentValue(test,ArgumentSource.Literal) }
}
});

Expand All @@ -87,7 +88,7 @@ public async Task WhenDeclaringAsyncQueryThenGenerationIsAsExpected()

schema.Initialize();

var type = schema.FindType("TestQuery") as ObjectGraphType<object>;
var type = schema.AllTypes["TestQuery"] as ObjectGraphType<object>;

Assert.NotNull(type);
Assert.NotEmpty(type.Fields);
Expand All @@ -98,9 +99,9 @@ public async Task WhenDeclaringAsyncQueryThenGenerationIsAsExpected()
var test = 6;
var result = ((Task<object>)field.Resolver.Resolve(new ResolveFieldContext()
{
Arguments = new Dictionary<string, object>()
Arguments = new Dictionary<string, ArgumentValue>()
{
{ "test", test }
{ "test", new ArgumentValue(test,ArgumentSource.Literal) }
}
})).Result;

Expand All @@ -115,7 +116,7 @@ public void WhenDeclaringBooleanQueryWithNameThenGenerationIsAsExpected()

schema.Initialize();

var type = schema.FindType("TestQuery") as ObjectGraphType<object>;
var type = schema.AllTypes["TestQuery"] as ObjectGraphType<object>;

Assert.NotNull(type);
Assert.NotEmpty(type.Fields);
Expand All @@ -126,10 +127,10 @@ public void WhenDeclaringBooleanQueryWithNameThenGenerationIsAsExpected()
var test = true;
var result = field.Resolver.Resolve(new ResolveFieldContext()
{
Arguments = new Dictionary<string, object>()
{
{ "test", test }
}
Arguments = new Dictionary<string, ArgumentValue>()
{
{ "test", new ArgumentValue(test,ArgumentSource.Literal) }
}
});

var expectedResult = (new Controller()).Boolean(test);
Expand All @@ -143,7 +144,7 @@ public void WhenDeclaringQueryWithDefaultValueThenGenerationIsAsExpected()

schema.Initialize();

var type = schema.FindType("TestQuery") as ObjectGraphType<object>;
var type = schema.AllTypes["TestQuery"] as ObjectGraphType<object>;

Assert.NotNull(type);
Assert.NotEmpty(type.Fields);
Expand Down
9 changes: 8 additions & 1 deletion src/GraphQL.SchemaDeclare/AddGraphQLSchemaDeclareService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace GraphQL.SchemaDeclare
{
public static class GraphQLSchemaDeclareServiceExtension
{
public static void AddGraphQLSchemaDeclareService(this IServiceCollection services, Action<TypeToGraphTypeTransformerOptions> setTypeToGraphTypeOptions = null)
public static void AddGraphQLSchemaDeclareService(
this IServiceCollection services,
Action<TypeToGraphTypeTransformerOptions> setTypeToGraphTypeOptions = null,
Func<ClrToGraphTypeMappings> clrToGraphTypeMappingsFactory = null)
{
services.AddSingleton<GraphQL.SchemaDeclare.GenerationServices.IExpressionToFieldInfoGenerator,
GraphQL.SchemaDeclare.GenerationServices.ExpressionToFieldInfoGenerator>();
Expand All @@ -33,6 +36,10 @@ public static void AddGraphQLSchemaDeclareService(this IServiceCollection servic
}
else
services.AddSingleton<GraphQL.SchemaDeclare.GenerationServices.TypeToGraphTypeTransformerOptions>();

services.AddSingleton(clrToGraphTypeMappingsFactory != null
? clrToGraphTypeMappingsFactory()
: new ClrToGraphTypeMappings());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;

namespace GraphQL.SchemaDeclare.GenerationServices
{
public class ClrToGraphTypeMappings : Dictionary<Type, Type>
{
}
}
Loading