I am new to HotChocolate and GraphQL as a whole and am trying to grasp on enabling Nodes and/or Relay support for my GraphQL API. Currently using HotChocolate v12.
Context I am trying to create a mutation that updates an entity (Client in this example). I am using code-first approach here and have the following:
- An input record/class is defined as follows:
public record UpdateClientInput([ID(nameof(Client))] int Id, string Code, string Name, string Subdomain);
- The mutation function which returns the payload class:
[UseAppDbContext]
public async Task<UpdateClientPayload> UpdateClientAsync(UpdateClientInput input, [ScopedService] AppDbContext context)
{
var client = await context.Set<Client>().FirstOrDefaultAsync(x => x.Id == input.Id);
// cut for brevity
return new UpdateClientPayload(client);
}
- I have enabled support for Nodes by adding this in the services configuration:
builder.Services
.AddGraphQLServer()
.AddQueryType(d => d.Name("Query"))
.AddMutationType(d => d.Name("Mutation"))
// removed others for brevity
.AddGlobalObjectIdentification()
.AddQueryFieldToMutationPayloads();
But yet when I browse the API using Banana Cake Pop, the UpdateClientInput object in the schema definition still uses int instead of the ID! (see screenshot below). So the GraphQL client I am using (Strawberry Shake) generates the input object that does not use the ID! type. Am I missing something here?
So to solve this problem, this was actually a change in HotChocolate v12 where records should use the [property: ID] instead of the [ID] attribute. That change is found here https://chillicream.com/docs/hotchocolate/api-reference/migrate-from-11-to-12#records.
What I did is to change the record declaration from:
to
that generated this input object as: