Skip to content

Commit

Permalink
Fix for "Unexpected type" error (#197 #205)
Browse files Browse the repository at this point in the history
* Revert Make GraphTypeInfo.TypeParameter lazy (#8)

* Revert Make GraphTypeInfo.TypeParameter lazy

* Version bumps

* Fix version bump for GraphQL

* "Unexpected type: " error fix

hacky fix for "Unexpected type: " error when return type of resolver method is INode

* Restore 'GraphTypeInfo'

* Added unique version suffix 

we needed a way to have unique name for out own nuget feed

* commetns resolved

* removed version suffix

* set a proper csproj file version

Co-authored-by: K-Pavlov <[email protected]>
Co-authored-by: Rob Wijkstra <[email protected]>
Co-authored-by: Rob Wijkstra <[email protected]>
  • Loading branch information
4 people authored Jun 10, 2020
1 parent 290bf44 commit 01de3af
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/GraphQL.Conventions/Adapters/GraphTypeAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ public ISchema DeriveSchema(GraphSchemaInfo schemaInfo)
var possibleTypes = interfaces
.Where(t => !t.IsIgnored)
.SelectMany(t => t.PossibleTypes)
.Select(typeInfo => (typeInfo.IsIgnored || !typeInfo.IsNullable || typeInfo.Interfaces.Any(x => x.IsIgnored == true))
? null
: DeriveType(typeInfo)
)
.Where(x => x != null)
.GroupBy(t => t.Name)
.Select(g => g.First());
.Select(g => g.First())
.ToArray();
var schema = new Schema(new FuncDependencyResolver(DeriveTypeFromTypeInfo))
{
Query = DeriveOperationType(schemaInfo.Query),
Mutation = DeriveOperationType(schemaInfo.Mutation),
Subscription = DeriveOperationType(schemaInfo.Subscription),
};
schema.RegisterTypes(possibleTypes
.Where(t => !t.IsIgnored && !t.Interfaces.Any(i => i.IsIgnored))
.Select(t => DeriveType(t).GetType())
.ToArray());
};
schema.RegisterTypes(possibleTypes);
return schema;
}

Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Conventions/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[assembly: AssemblyCopyright("Copyright 2016-2019 Tommy Lillehagen. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("2.5.3")]
[assembly: AssemblyInformationalVersion("2.5.3")]
[assembly: AssemblyFileVersion("2.5.4")]
[assembly: AssemblyInformationalVersion("2.5.4")]
[assembly: CLSCompliant(false)]

[assembly: InternalsVisibleTo("Tests")]
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/GraphQL.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>GraphQL Conventions for .NET</Description>
<VersionPrefix>2.5.3</VersionPrefix>
<VersionPrefix>2.5.4</VersionPrefix>
<Authors>Tommy Lillehagen</Authors>
<TargetFrameworks>net45;netstandard1.6.1</TargetFrameworks>
<DepsFileGenerationMode>old</DepsFileGenerationMode>
Expand Down
56 changes: 56 additions & 0 deletions test/GraphQL.Conventions.Tests/Adapters/BugUnexpectedTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using GraphQL.Conventions;
using GraphQL.Conventions.Relay;
using GraphQL.Conventions.Tests;
using GraphQL.Conventions.Tests.Templates;
using GraphQL.Conventions.Tests.Templates.Extensions;
using System.Threading.Tasks;

namespace Tests.Adapters.Engine.Bugs
{
public class BugUnexpectedTypeTests : TestBase
{
[Test]
public async Task Can_Resolve_NonNull_Null_Query()
=> await Can_Resolve_Query_Private<NonNull_Null_Query>();

[Test]
public async Task Can_Resolve_Null_NonNull_Query()
=> await Can_Resolve_Query_Private<Null_NonNull_Query>();

private async Task Can_Resolve_Query_Private<TQuery>()
{
var engine = GraphQLEngine
.New<TQuery>();
var result = await engine
.NewExecutor()
.WithQueryString("query { node { ... on ParentNode { id, nested { id } } } }")
.Execute();
result.ShouldHaveNoErrors();
result.Data.ShouldHaveFieldWithValue("node", "id", "UGFyZW50Tm9kZTox");
result.Data.ShouldHaveFieldWithValue("node", "nested", "id", "Q2hpbGROb2RlOjE=");
}

public class NonNull_Null_Query
{
public INode Node() => new ParentNode();
public NonNull<ParentNode> A() => null;
public ParentNode B() => null;
}

public class Null_NonNull_Query
{
public INode Node() => new ParentNode();
public ParentNode A() => null;
public NonNull<ParentNode> B() => null;
}
public class ChildNode : INode
{
public Id Id => Id.New<ChildNode>(1);
}
public class ParentNode : INode
{
public Id Id => Id.New<ParentNode>(1);
public ChildNode Nested() => new ChildNode();
}
}
}

0 comments on commit 01de3af

Please sign in to comment.