Skip to content

Implicit conversion in IdGraphType adapter #219

@baluubas

Description

@baluubas

We're in the process of upgrading from 2.x to 4.0.0 and I'm having some trouble in my schema where we have a nullable id Graph.Convention.Id? . When serializing a response where the id is null we a get:

System.AggregateException: One or more errors occurred. (Unable to decode identifier ''.) ---> GraphQL.Conventions.Execution.FieldResolutionException: Unable to decode identifier ''. ---> System.ArgumentException: Unable to decode identifier ''. at GraphQL.Conventions.Id..ctor(String encodedIdentifier) at GraphQL.Conventions.Id.op_Implicit(String encodedIdentifier) at GraphQL.Conventions.Adapters.Types.IdGraphType.ParseValue(Object value) at GraphQL.Types.IdGraphType.Serialize(Object value) in /_/src/GraphQL/Types/Scalars/IdGraphType.cs:line 70 at GraphQL.Execution.ExecutionStrategy.CompleteNode(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 471 --- End of inner exception stack trace --- 

There seem to be a implicit conversion going on as this failing test illustrate:

using GraphQL.Conventions.Adapters.Types; using Tests.Templates; namespace Tests.Types { public class IdGraphTypeTests : TestBase { [Test] public void Can_Handle_Null_ParseValues() { var graphType = new IdGraphType(); Assert.IsNull(graphType.ParseValue(null)); } } } 

Our workaround at the moment is to replace the IdGraphType the following version that does not result in the automatic conversion.

 public class WorkaroundForNotBeingAbleToHaveNullableIds : IdGraphType { public override object ParseValue(object value) { if (value == null) { return null; } return new Id(value.ToString()); } } 

I'm not so familiar with the inner workings of the framework so I can't say if this is a bug or if we are somehow using this wrong. What do you recon?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions