0

When I use GraphQL (hot chocolate) together with MongoDB and abstract classes, I receive the following error message:

An error occurred while deserializing the Resource property of class 
MyClass:
Cannot create an instance of MySampleClass because it is an abstract class.

MySampleClass is abstract but there is a registered type map. Querying data normally works, but using it together with a GraphQL throws the following exception:

at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)    
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)    
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)    
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)    at 
MongoDB.Driver.Core.Operations.CursorBatchDeserializationHelper.DeserializeBatch[TDocument](RawBsonArray batch, IBsonSerializer`1 documentSerializer, 
MessageEncoderSettings messageEncoderSettings)    at MongoDB.Driver.Core.Operations.FindOperation`1.CreateFirstCursorBatch(BsonDocument cursorDocument)    
at MongoDB.Driver.Core.Operations.FindOperation`1.CreateCursor(IChannelSourceHandle channelSource, IChannelHandle channel, BsonDocument commandResult)    at 
MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)    at 
MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)    at 
MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)    at 
MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)    
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)    
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)    
at HotChocolate.Data.MongoDb.MongoDbFindFluentExecutable`1.ToListAsync(CancellationToken cancellationToken)    
at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)    
at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)

I've tried several types of registration and setting a deserialization context, but could not find any way to solve the problem.

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • i doubt it has anything common with graphql. When you query something you should specify a destination type not an interface or abstract class. AFAIK registering class type map doesn't work here – dododo Jan 03 '23 at 14:28
  • @dododo that is not correct. This is natively supported by hot chocolate: https://chillicream.com/docs/hotchocolate/defining-a-schema/interfaces – BendEg Jan 03 '23 at 15:31

0 Answers0