I'm getting this error when trying to update an `e...
# orm-help
j
I'm getting this error when trying to update an
event
with a new array of `places`:
Reason: 'places' Expected 'PlaceUpdateManyInput', found not an object
Copy code
const UPDATE_EVENT_MUTATION = gql`
  mutation UpdateEventMutation($id: ID!, $title: String!, $slug: String!, $description: String, $dates: [String], $places: [PlaceInput]) {
    updateEvent(id: $id, title: $title, slug: $slug, description: $description, dates: $dates, places: $places) {
      id
      title
      description
      dates
      places {
        name
        url
      }
    }
  }
`;

// Resolver
updateEvent(parent, { id, title, slug, description, dates, places }, context) {
     return context.prisma.updateEvent({
       where: { id },
       data: { title, slug, description, dates: { set: dates }, places },
     });
   },

// graphql schema
type Mutation {
  updateEvent(id: ID!, title: String!, slug: String!, description: String, dates: [String], places: [PlaceInput]): Event
}

input PlaceInput {
  name: String!
  url: String
}

type Place {
  id: ID!
  name: String!
  url: String
}

type Event {
  id: ID!
  slug: String!
  title: String!
  description: String
  dates: [String]
  places: [Place]
  menus: [String]
}
@marcus @Harshit any idea of what could be wrong with my resolver?
m
Your call to Prisma does not use the nested mutation correctly. It is an just the array of places but it has to be an object that specifies the kind of nested mutation
j
thanks, is it the
connect
or the
create
that I have to use?
sorry for asking many questions. I'm still learning about prisma & graphql and this part of updating the nested objects is what I find most difficult to understand
with
places: { create: places }
, I was able to save data, but it doesn't update it. It keeps increasing the records
with this:
Copy code
places: {
           update: {
             where: { id },
             data: { places }
           }
         }
I though it would update each place but it throws an error
I give up for now. Too much frustration and feeling sleepy. This is hard.
is this the correct way of doing it?
Copy code
places: {
           update: {
             where: { id: places.id },
             data: {
               name: places.name,
               url: places.url
             }
           }
         }
m
@joan: I don’t know. What do you want to exactly achieve? What should happen with the places?
j
Hi marcus. I managed to understand how it works and I fixed it by using
connect
when adding places
👍 1
What I want to do now is to add
subscriptions
to update the UI whenever a new
place
is added