How to return all fields of an object in a Mutation in Graphql?

Asked

Viewed 74 times

0

Hello,

I have a mutation in the GraphQL (With Rails) and I want to perform a database update using this mutation. When he finishes udpate, return the entire object as a response.

Come on.

I have a table Users in the database. Let’s say that in the table of this database I have the following fields:
ID | name | birthday | phone | email

And I want to change the name of one of his, so Mutation will be:

mutation {
  updateUser(
    id: 6,
    name: "Usuário 02"
  ) {
    name
  }
}

After I pass the argument: value (name: "User 02") I can tell you what fields I want in this answer mutation.

My doubt is there.

I don’t want to pass any field as an answer but when that happens, I want all the fields in the table to be returned, that is, the complete object (For those who are in doubt, User is my object rsrs).

Is that even possible? Could you give me some guidance on how to do?

Please read and if you do not understand any part, I ask you to comment here below that I already draw the doubt :)

Grateful to all who help!

  • Worth reading: https://productionreadygraphql.com/blog/2019-10-24-why-you-cant-select-all-fields-on-a-type-in-graphql.

1 answer

0

It is not possible to return all fields of an object implicitly. In Graphql you must be explicit with what you want your query to return.

Whatever solution you have for this can be considered gambiarra. Mindset when using Graphql is different.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.