Open ryanvanderpol opened 5 years ago
@ryanvanderpol I think what is wrong is that you need to do two things. First, separate out your find and patch query, secondly add an EAGER to your patch to pull in the pets, and third use the patchAndFetch
instead of just patch. Here is an untested example but it is similar to what is working for me:
resolve: async (root, userData) => {
const { id, first_name, last_name } = userData;
const updating = await Person.query().findById(id);
return await updating.$query().eager('pets').patchAndFetch({ first_name, last_name });
}
Thanks, @DaKaZ. in my OP I noted that a pet
also has toys
. Would I need to add toys
to the eager
list? And if that's the case, what happens when I have way, way more complex objects that are nested way deeper than this? I need to explicitly add everything to the eager
query?
I guess my question is, why can't I get a mutation to work like the built-in Objection.js types? Using the built-in .model
types the query can dynamically load the return object and its nested types based on the GraphQL request -- I just want my mutations to return objects using the same behavior.
This might not be ideal depending on your project, but you can refetch the query after performing the mutation. Apollo boost has this an option when making a query.
If performance is a concern, and you don't want to eager
load all of the relations, you'll have to traverse the ast and find the relations being requested. You can see an example how to do that in the SchemaBuilder class: https://github.com/Vincit/objection-graphql/blob/master/lib/SchemaBuilder.js#L301
I have a mutation defined as follows
Which I call from my app like
The mutation part works fine, but when the data is returned from the server, it's missing the
pets
object and everything below it. Interestingly (maybe),pets
actually comes back asnull
rather than being omitted completely, so it seems like maybe it tried to complete the relation, but nothing came back.Any idea what could be going on here?