0

I have a relatively simple schema: Bands, Venues and Shows. Shows must each have a Venue; a Show can have multiple Bands. I want to have a mutation called addBandsToShow and right now my schema looks something like this:

 type Mutation {
    addBandsToShow(input: [Band]!): Show
  }
  type Band {
    id: Int!
    slug: String!
    name: String!
    shows: [Show]
  }
  type Show {
    id: Int!
    description: String!
    datetime: String!
    venue: Venue
    bands: [Band]
  }

My goal is to create a mutation which takes potentially multiple bands as an argument and associates them with the show.

The above schema yields an Error, Error: The type of Mutation.addBandsToShow(input:) must be Input Type but got: [Band]! but I don't want to create a new Band here; I want to add a Band which already exists in the graph to the list of bands associated with a Show. (ultimately this is managed in a relational DB) I'm a little lost on how to accomplish this, short of just supplying a list of band ids. But maybe that's the only way to do this?

Scelerat
  • 11
  • 2
  • First thing, you are getting the error, because you are providing Type Band to input which won't accept it, it should be of type Input Band. Secondly, if you want to add an existing band to the show, you should have ids or any unique parameter to identify the band in database and add it to a particular show. – Rakesh Jain Mar 19 '20 at 23:29
  • A list of IDs would be the best thing to use in this particular case, unless there's other information about the relationship that you want to include (e.g. the length of the appearance, the set list, etc.). The type of your `input` argument *can* be an object, but the argument's type must be an input object type, not a regular object type. See the linked post for details. – Daniel Rearden Mar 19 '20 at 23:29
  • So is that simply the recommended way to make associations between related objects? Just supply the unique id or foreign key (whatever) that links them? That's what I have been doing, and I wasn't entirely certain that was The GraphQL Way – Scelerat Mar 20 '20 at 00:53

0 Answers0