1

I am currently learning graphql and I am not sure if I correctly understand how mutations are supposed to work, especially when combined with subscriptions.

I have a page with client details, that include a description and a list of software products he has purchased from our company. In the interface there is one edit button for the description, a plus button to add a new software product to the client's list and minus buttons for each product to enable removing them.
I currently added a mutation that takes the id of the client and a string (newDescription) as parameters and updates the client's description. Is that right or should I have the id and a ClientInputType (containing a field description) and pass those as parameters? More importantly, if I use the ClientInputType and it contains both the description and the list of software products, is there a way I can update only one field at a time (in order to update the client using the same mutation, but change only the required fields depending on which button was pressed in the interface)?

public Mutation(IClientRepository clientRepository) { this.FieldAsync<ClientType>( "updateClient", arguments: new QueryArguments( new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "id" }, new QueryArgument<StringGraphType> { Name = "newDescription" } ), resolve: async ctx => {...} }

In other words, can I let graphql know, in any way, that I want to update only one field in the ClientInputType and that it should ignore the others? What should a mutation return? I am curently returning the updated client.

kanpeki
  • 435
  • 2
  • 6
  • 20
  • You can always create a mutation to update that specific field with ClientInputType that contains id and description. This can call a method in your repo to update only that filed. Make sure your clienttype mirrors whatever your returning in your repo. – Ray Sep 11 '19 at 16:07

0 Answers0