I'm setting a one to many relations by connecting ...
# orm-help
z
I'm setting a one to many relations by connecting array of ids - but existing connections are kept intact - is there no way to clear them all before adding new?
Copy code
mutation {
  updateStation(
    where: { id: "S8Cdjsc3DsPvuQJp1ZlSMGfej" }
    data: {
      editors: {
        connect: [
          { id: "aZGL8IkcULGPNFdUZG37Qc1kX" }
          { id: "1coBflfBj8prHe4USggSbG49J" }
          { id: "4Kr8VGxMHys3hH5B0pJDighRc" }
          { id: "54lPfOvRAMXljSk7wlJp6r29N" }
        ]
      }
    }
  ) {
    id
    title
    editors {
      id
      name
    }
  }
}
l
you can query all the station ID you want to disconnect and stock them in an array and use UpdateManyStation for you as this exemple ===> data: { posts: { disconnect: [{ }] } }
disconnect: YOURVARIABLE
message has been deleted
z
could I disconnect and connect in same mutation ?
l
yes use await
async
z
no I mean in just run
UpdateManyStation
once?
so like
Copy code
editors: {disconnect: {...},
connect: [{...}]
l
i would like to know if it works never tried
can you try and tell me ?
🙂
z
I'll do, closing for tonight but first thing tomorrow
I was hoping there was a easier way.. a shortcut perhaps but I guess there is no such thing?
l
Ok thanks, so answer in this talk tomorrow 😉 unfortunately i dont think for this maybe in a futur update
z
I was too curious... tried it and it didn't work but interestingly no error
disconnect was run so all connections where removed but none added
or just a sec... it semms it's actually adding the diff
hey presto... yes indeed it's working!
👍 1
l
ok so you can disconnect and connect in the same mutation
interesting
z
well it worked in playground but it seems there are errors in resolver
I'm trying to figure out where they're coming from
this
Copy code
{ where: { id: 'S8Cdjsc3DsPvuQJp1ZlSMGfej' },
  data:
   { title: 'Æðaskurðlækningar',
     description: '',
     url: 'dsafdsa',
     entryDescriptions: 'SHOWFULL',
     editors:
      { disconnect:
         [ { id: { id: '58XTALpjdRPLTzKZRHni1tSBr' } },
           { id: { id: '7ufSBWILdPZdc2z3stVyQZOq0' } },
           { id: { id: '81TH4o2lnZEzLYgkvtoNpRIVC' } },
           { id: { id: '92G4thiwmXMQA0eOQYnroPl03' } },
           { id: { id: '9ygFYOt4YyYQuhufZ9rR4T8rY' } } ],
        connect:
         [ { id: 'xe0WoEJANTPJCKDWYbx5UbClo' },
           { id: '81TH4o2lnZEzLYgkvtoNpRIVC' },
           { id: '92G4thiwmXMQA0eOQYnroPl03' },
           { id: '9ygFYOt4YyYQuhufZ9rR4T8rY' },
           { id: '7ufSBWILdPZdc2z3stVyQZOq0' },
           { id: '58XTALpjdRPLTzKZRHni1tSBr' } ] },
     lastUpdatedAt: '2018-10-28T01:08:35.994Z',
     lastUpdatedBy: { connect: { id: 'o5FGT6i1xyGEMRXShMPU71ZGd' } } } }
gives this error...
Copy code
Error: Variable "$_v0_data" got invalid value {"title":"Æðaskurðlækningar","description":"","url":"dsafdsa","entryDescriptions":"SHOWFULL","editors":{"disconnect":[{"id":{"id":"58XTALpjdRPLTzKZRHni1tSBr"}},{"id":{"id":"7ufSBWILdPZdc2z3stVyQZOq0"}},{"id":{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"}},{"id":{"id":"92G4thiwmXMQA0eOQYnroPl03"}},{"id":{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"}}],"connect":[{"id":"xe0WoEJANTPJCKDWYbx5UbClo"},{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"},{"id":"92G4thiwmXMQA0eOQYnroPl03"},{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"},{"id":"7ufSBWILdPZdc2z3stVyQZOq0"},{"id":"58XTALpjdRPLTzKZRHni1tSBr"}]},"lastUpdatedAt":"2018-10-28T01:08:36.005Z","lastUpdatedBy":{"connect":{"id":"o5FGT6i1xyGEMRXShMPU71ZGd"}}}; Expected type ID at value.editors.disconnect[0].id; Cannot convert object to primitive value
Variable "$_v0_data" got invalid value {"title":"Æðaskurðlækningar","description":"","url":"dsafdsa","entryDescriptions":"SHOWFULL","editors":{"disconnect":[{"id":{"id":"58XTALpjdRPLTzKZRHni1tSBr"}},{"id":{"id":"7ufSBWILdPZdc2z3stVyQZOq0"}},{"id":{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"}},{"id":{"id":"92G4thiwmXMQA0eOQYnroPl03"}},{"id":{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"}}],"connect":[{"id":"xe0WoEJANTPJCKDWYbx5UbClo"},{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"},{"id":"92G4thiwmXMQA0eOQYnroPl03"},{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"},{"id":"7ufSBWILdPZdc2z3stVyQZOq0"},{"id":"58XTALpjdRPLTzKZRHni1tSBr"}]},"lastUpdatedAt":"2018-10-28T01:08:36.005Z","lastUpdatedBy":{"connect":{"id":"o5FGT6i1xyGEMRXShMPU71ZGd"}}}; Expected type ID at value.editors.disconnect[1].id; Cannot convert object to primitive value
Variable "$_v0_data" got invalid value {"title":"Æðaskurðlækningar","description":"","url":"dsafdsa","entryDescriptions":"SHOWFULL","editors":{"disconnect":[{"id":{"id":"58XTALpjdRPLTzKZRHni1tSBr"}},{"id":{"id":"7ufSBWILdPZdc2z3stVyQZOq0"}},{"id":{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"}},{"id":{"id":"92G4thiwmXMQA0eOQYnroPl03"}},{"id":{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"}}],"connect":[{"id":"xe0WoEJANTPJCKDWYbx5UbClo"},{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"},{"id":"92G4thiwmXMQA0eOQYnroPl03"},{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"},{"id":"7ufSBWILdPZdc2z3stVyQZOq0"},{"id":"58XTALpjdRPLTzKZRHni1tSBr"}]},"lastUpdatedAt":"2018-10-28T01:08:36.005Z","lastUpdatedBy":{"connect":{"id":"o5FGT6i1xyGEMRXShMPU71ZGd"}}}; Expected type ID at value.editors.disconnect[2].id; Cannot convert object to primitive value
Variable "$_v0_data" got invalid value {"title":"Æðaskurðlækningar","description":"","url":"dsafdsa","entryDescriptions":"SHOWFULL","editors":{"disconnect":[{"id":{"id":"58XTALpjdRPLTzKZRHni1tSBr"}},{"id":{"id":"7ufSBWILdPZdc2z3stVyQZOq0"}},{"id":{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"}},{"id":{"id":"92G4thiwmXMQA0eOQYnroPl03"}},{"id":{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"}}],"connect":[{"id":"xe0WoEJANTPJCKDWYbx5UbClo"},{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"},{"id":"92G4thiwmXMQA0eOQYnroPl03"},{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"},{"id":"7ufSBWILdPZdc2z3stVyQZOq0"},{"id":"58XTALpjdRPLTzKZRHni1tSBr"}]},"lastUpdatedAt":"2018-10-28T01:08:36.005Z","lastUpdatedBy":{"connect":{"id":"o5FGT6i1xyGEMRXShMPU71ZGd"}}}; Expected type ID at value.editors.disconnect[3].id; Cannot convert object to primitive value
Variable "$_v0_data" got invalid value {"title":"Æðaskurðlækningar","description":"","url":"dsafdsa","entryDescriptions":"SHOWFULL","editors":{"disconnect":[{"id":{"id":"58XTALpjdRPLTzKZRHni1tSBr"}},{"id":{"id":"7ufSBWILdPZdc2z3stVyQZOq0"}},{"id":{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"}},{"id":{"id":"92G4thiwmXMQA0eOQYnroPl03"}},{"id":{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"}}],"connect":[{"id":"xe0WoEJANTPJCKDWYbx5UbClo"},{"id":"81TH4o2lnZEzLYgkvtoNpRIVC"},{"id":"92G4thiwmXMQA0eOQYnroPl03"},{"id":"9ygFYOt4YyYQuhufZ9rR4T8rY"},{"id":"7ufSBWILdPZdc2z3stVyQZOq0"},{"id":"58XTALpjdRPLTzKZRHni1tSBr"}]},"lastUpdatedAt":"2018-10-28T01:08:36.005Z","lastUpdatedBy":{"connect":{"id":"o5FGT6i1xyGEMRXShMPU71ZGd"}}}; Expected type ID at value.editors.disconnect[4].id; Cannot convert object to primitive value
but same mutation works 100% in playground
l
{ where: { id: 'S8Cdjsc3DsPvuQJp1ZlSMGfej' }, data: { title: 'Æðaskurðlækningar', description: '', url: 'dsafdsa', entryDescriptions: 'SHOWFULL', editors: { disconnect: [ { id: '58XTALpjdRPLTzKZRHni1tSBr' }, { id: '7ufSBWILdPZdc2z3stVyQZOq0' }, { id: '81TH4o2lnZEzLYgkvtoNpRIVC' }, { id: '92G4thiwmXMQA0eOQYnroPl03' }, { id: '9ygFYOt4YyYQuhufZ9rR4T8rY' } ], connect: [ { id: 'xe0WoEJANTPJCKDWYbx5UbClo' }, { id: '81TH4o2lnZEzLYgkvtoNpRIVC' }, { id: '92G4thiwmXMQA0eOQYnroPl03' }, { id: '9ygFYOt4YyYQuhufZ9rR4T8rY' }, { id: '7ufSBWILdPZdc2z3stVyQZOq0' }, { id: '58XTALpjdRPLTzKZRHni1tSBr' } ] }, lastUpdatedAt: '2018-10-28T010835.994Z', lastUpdatedBy: { connect: { id: 'o5FGT6i1xyGEMRXShMPU71ZGd' } } } }
try this
z
oh lord...
Copy code
editors: {
          disconnect: currentEditors.map(ce => ({ id: ce.id })),
          connect: editors.map(es => ({ id: es }))
        },
👍 1
this fixed it...
ce.id
not
ce
and caused the double brackets
... it works in resolver as well!
l
NICE well done
z
thx... pretty good yes for saturday night 🙂