1

I wrote the following object type class.

public class ResponseType<T> : ObjectType<ResponseEntry<T>>
{
    protected override void Configure(IObjectTypeDescriptor<ResponseEntry<T>> descriptor)
    {
        descriptor.Name("Response");
    }
}

I want to use it like this as the outermost type in the resolver definition.

descriptor.Field<SharedResolvers>(r => r.GetObject1(default, default, default, default))
    .Type<ResponseType<ListType<Object1>>>()
    .Name("object1");

descriptor.Field<SharedResolvers>(r => r.GetObject2(default, default, default, default))
    .Type<ResponseType<ListType<Object2>>>()
    .Name("object2");

This code works if I only implement object1 however as soon as I add object2 I get the following error.

System.Collections.Generic.KeyNotFoundException: 'The given key 'HotChocolate.Configuration.RegisteredType' was not present in the dictionary.'

It seems as though there may be some issue with declaring two resolvers of the same class type. Is that the case? And if so, what are my options?

1 Answers1

2

I was able to resolve the issue by setting the descriptor.Name to a unique value based on T.

descriptor.Name($"Response_{typeof(T).GetHashCode()}");

Then I realized my real issue was that I was defining the name at all. If you don't override the name it automatically comes up with a unique name/key based on the type definition.