-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable nested relationships in mutation inputs #294
Comments
thanks, I'll take a look |
Thanks @olirice. Let me know if and how I could help to achieve these enhancements. |
@olirice I made a post in the discord channel (ref: https://discord.com/channels/839993398554656828/1063824664520044557) and I think it might be related to this as well. Basically I want to insert one-to-one relationships in one go, but I am not sure you can do that as of now. |
hi @HadiSDev
the graphql spec doesn't have a method for referring to a values return in a previous operation in multi-mutation inserts. The behavior you're looking for would be supported by the feature this thread describes. We're currently knocking out user defined functions and then revamping inserts will be the next feature on the agenda (nested inserts and upsert) so there should be movement on this soon |
Can I also request y'all add some notice to the docs that says "In case you're looking for this one popular GraphQL feature; we don't have it yet, JFYI"? I am feeling pretty let down after spending a lot of time switching to GraphQL to take advantage of this specific capability, only to find out now that it isn't there at all. I decided to switch to GraphQL because once I got to some core parts of the user flow that require these multi-table inserts. I could already do multi-table queries with the supabase-js client; but I wanted these inserts done right; in a good "serverless" way that feels good for users. I thought, maybe I'll use a supabase server function, or maybe an RPC function, or maybe an edge function/lambda -- but I saw pg_graphql was here to solve exactly this problem for me. I read your blog post and it gives a code example of a mutation and then says "For a complete example with relationships, check out the API docs." ... so... I thought, no problem. I even skimmed those docs at the time but it wasn't until I got back to the feature that started the whole switch that I read close enough to realize that mutations with relationships are just not mentioned on the page anywhere and I simply can't do them. Anyway, my b. I will look forward to this feature when it is ready, and I appreciate your response and the context/info on this thread. But please consider adding a note to the docs and possibly also as an edit to the blog post, i.e. "For a complete example showing queries with relationships, check out the API docs. (Mutations with relationships are not yet supported.)" It would have saved me a lot of work. |
The two major modes here are inserting nested objects where
I got the chance to review the Hasura style mutation insertBookWithAuthor {
insertIntoBookCollection(objects: [
{
title: "Some Title",
author: {
object: {
id: 1
name: "Some Author"
},
onConflict: {
constraint: id,
update_columns: [name]
where: ...
}
},
}
]) {
returning {
...
}
}
} Pros:
Cons:
The first step will be implementing upsert logic in the existing mutations so we'll start there and see how it goes |
Another option for implementation inspiration, could be Laravel Lighthouse. I personnaly prefer it than the Hasura one (but I'm not a specialist), it's more clear what operation is done and that you can have multiple operation at the same time. Basically they offer neasted mutation with those operations:
That are reflected in the schema like this:
For reference see Lighthouse docs: Nested Mutations |
Thank you for the work, guys. Do you are able to provide an ETA for this feature? |
Hi @bpbastos, we have work in progress on exposing user defined function as queries/mutations. Once we are done with that, then we can pick this up. I know this is not exactly an ETA but maybe enough information to give you an idea. |
Thank you, @imor. Exposing user-defined functions as queries/mutations will do the trick for a while. Do you happen to know if I can define a JSON object as a parameter in my functions? If that's possible, I could implement my own logic for handling nested inputs. |
Yes, we do plan to support JSON types as function parameters. |
Any updates on when it's going to be available to use? |
we're still working on UDF in #393 but thats down to the last few nits no timeline on this releasing but work should start soon after ^ |
Hey, thanks for the amazing work on pg_graphql! |
I can't say for sure that it's near-term as in weeks, but we now have UDF in a good place so the precursor to this feature (upsert functionality) is next on the agenda |
Is this feature available yet? Would really be nice to have. |
not yet but we have a WIP for upserts which is a prerequisites we haven't lost sight of this goal but I recognize the timeline is dragging on! |
I'd like to gently reiterate support for this feature! Would alleviate quite the technical debt with the needed workarounds. Once again, thank you for your hard work! |
Would be a killer feature 👍 |
Describe the bug
It's not possible to insert an object along with its related object(s) in a single mutation. But that's exactly the beauty of GraphQL!
To Reproduce
Consider the following simple extract of a schema (
Query
,update
,delete
and all other types omitted for simplicity), where basically we have a One-To-Many relationship betweenPost
andPostImage
tables:Since I usually create a
PostImage
row every time I create aPost
row, I need to execute two separate mutations to achieve this.First:
And after getting the result from
CreatePost
, I can execute:Expected behavior
Expose nested objects in mutation inputs, so that I can directly create a
Post
along with aPostImage
with just one mutation:See Hasura docs on this topic for reference.
Versions:
The text was updated successfully, but these errors were encountered: