Why HotChocolate does not use the input typename instead of described type name?

99 Views Asked by At

I have the following mutation in my schema which uses DocumentGraphQlInput as input type. But when I take a look at the schema in StrawberryShake I see that the type name is used (with Input suffix) which is described as DocumentGraphQlInput.

What I describe below is the right behaviour and my expectations a wrong, or this is a bug?

It looks like to me HotChocolate goes back to the registered type (in this case DocumentInputContract with Input suffix, so it will be DocumentInputContractInput) instead of using the name it is registered which is DocumentGraphQlInput.

HotChocolate does the same to the return type. I registered DocumentOutputContract as DocumentGraphqlOutput (see the code below), but in StrewberryShake the return type is DocumentOutputContract, however, in my opinion, it should be DocumentGraphqlOutput.

public class AddDocumentMutation : ObjectTypeExtension<Mutation>
{
    protected override void Configure(IObjectTypeDescriptor<Mutation> descriptor)
    {
        descriptor
            .Field("addDocument")
            .Type<NonNullType<DocumentGraphqlOutput>>()
            .Description("Recording new documents in the system")
            .Argument("newDocument", arg => arg.Type<NonNullType<DocumentGraphqlInput>>())
            .ResolveWith<DocumentResolvers>(documentResolvers => documentResolvers.AddAsync(default, default));
    }
}

The resolver:

    public async Task<DocumentGraphqlOutput> AddAsync(
        IResolverContext resolverContext,
        IDocumentService documentService)
    {
        DocumentGraphqlInputType newDocumentGraphqlInputType =
            resolverContext.ArgumentValue<DocumentGraphqlInputType>("newDocument");
        return await documentService.AddAsync(newDocumentGraphqlInputType);
    }

Where DocumentGraphqlInput looks like below:

public class DocumentGraphqlInput : InputObjectType<DocumentInputContract>
{
    protected override void Configure(IInputObjectTypeDescriptor<DocumentInputContract> descriptor)
    {
        descriptor
            .Field(f => f.Id)
            .Description("Unique identifier of the entity")
            .Type<NonNullType<LongType>>();

        descriptor
            .Field(f => f.Name)
            .Description("Name of the entity")
            .Type<NonNullType<StringType>>();

        descriptor
            .Field(f => f.Description)
            .Description("Description of the entity")
            .Type<StringType>();

        descriptor
            .Field(f => f.Uri)
            .Description("The source url of the document")
            .Type<StringType>();
    }
}

But, StrawberryShake shows this:

type Mutation {
  """
  Recording new documents in the system
  """
  addDocument(newDocument: DocumentInputContractInput!): DocumentOutputContract!
}

However, it should be, I think, rather this:

type Mutation {
  """
  Recording new documents in the system
  """
  addDocument(newDocument: DocumentGraphqlInput!): DocumentGraphqlOutput!
}

The DocumentGraphqlOutput describes DocumentOutputContract like this:

public class DocumentGraphqlOutput : ObjectType<DocumentOutputContract>
{
    protected override void Configure(IObjectTypeDescriptor<DocumentOutputContract> descriptor)
    {
        descriptor
            .Field(f => f.Id)
            .Description("Unique identifier of the entity")
            .Type<NonNullType<FloatType>>();

        descriptor
            .Field(f => f.Name)
            .Description("Name of the entity")
            .Type<NonNullType<StringType>>();

        descriptor
            .Field(f => f.Description)
            .Description("Description of the entity")
            .Type<StringType>();

        descriptor
            .Field(f => f.Uri)
            .Description("The source url of the document")
            .Type<StringType>();
    }
}
1

There are 1 best solutions below

0
On

I created a small example to observe what is happening here. It seems what I described is the proper behaviour. The thing I did not like is that I used complicated naming standard for my classes.