Can I do a nested connection on a mutation?
# orm-help
s
Can I do a nested connection on a mutation?
h
Yes, but not in upsert
s
Could you show me an example of how it is done? Mine is throwing an error saying the field doesn’t exist.
a
But passing the array of data to the resolver function is the challenge. The only way I figured out to do it was to encode the array of data with
JSON.stringify()
and then do
JSON.parse()
in the resolver
Use docs there is everything 🙂
s
That’s not what I’m talking about. Something that conceptually accomplishes this effect:
Copy code
createItem({
  profile: {
    connect: {
      user: {
        connect: {
          id: SOME_ID
        }
      }
    }
  }
}, info)
I have a profile type that is separate from my actual users. I didn’t give Profiles an ID since they have a 1-1 relationship with users, but I suppose I have to?
h
I would suggest to you write mutation in playground it hints you syntax because your is wrong 🙂 you need to provide somekind info what user to connect from profile 🙂
Plus i think you can't connect nested records, you can use connect inside create
Just explore schema in playground and you will find out everything how it works 🙂
o
@Sam Jackson did u ever figure this out? I am trying to solve this as well
s
@orange_man Take out the first connect