Help with mutation for a relationship-as-a-type

I am just getting into working with GRANDStack and have found building out a schema to be really intuitive and enjoyable to work with.
However, I am trying to follow the example from the docs for creating a relationship as a type, as I seed my Neo4j instance. This is the example code:

type Movie {
  title: String
  year: Int
  ratings: [Rated]
}

type User {
  userId: ID
  name: String
  rated: [Rated]
}

type Rated @relation(name: "RATED") {
  from: User
  to: Movie
  rating: Float
  timestamp: Int
}

The mutations I am using are
export default /* GraphQL */ `
mutation {

movie1: CreateMovie (
  title: "First Movie Title"
  year: 1998
) {
  title
  year
}
user1: CreateUser (
  userId: "user1"
  name: "Gumby"
) {
  userId
  name
}
userrating1: AddMovieRatings (
  from: {userId: "user1"}
  to: {id: "246"}
  rating: 4.0
  timestamp: 2020
) {
  rating
  timestamp
}    

}
`;
I can add a movie and a user, but Apollo gives me a 400 error when running the seedDb script that indicates (in my limited experience) that something is wrong with the AddMovieRatings mutation. Since seedDb only breaks after I add that mutation to the code.
I have the following mutations, and I have tried using the AddUserRated mutation but get same error result. These are the auto generated mutations in the schema

type Mutation {
CreateMovie(title: String, year: Int): Movie
UpdateMovie(title: String!, year: Int): Movie
DeleteMovie(title: String!): Movie
AddMovieRatings(
from: _UserInput!
to: _MovieInput!
data: _RatedInput!
): _AddMovieRatingsPayload
RemoveMovieRatings(
from: _UserInput!
to: _MovieInput!
): _RemoveMovieRatingsPayload
CreateUser(userId: ID, name: String): User
UpdateUser(userId: ID!, name: String): User
DeleteUser(userId: ID!): User
AddUserRated(
from: _UserInput!
to: _MovieInput!
data: _RatedInput!
): _AddUserRatedPayload
RemoveUserRated(from: _UserInput!, to: _MovieInput!): _RemoveUserRatedPayload
}

I think I am missing something simple here? Thanks for any help

For clarification, I mean I am not calling the AddMovieRatings mutation correctly (not that there is something wrong with the mutation itself)
I have tried using the data prop like this too, with no luck:

userrating1: AddMovieRatings (
  from: {userId: "user1"}
  to: {id: "246"}
  data: {rating: 4.0, timestamp: 2020}
) {
  rating
  timestamp
} 

I am not sure if I am even calling the correct mutation to create the relationship? (The movie id I am using is a valid one.)

Hi @jgedmondson, I am having a similar issue Auto-generated Mutation Does Not Create Relationship. I see you posted this question more than two months ago, have you found a solution to your problem?
Thanks.

Nope, never found a solution.

No one from Neo4j commented, which is extremely disappointing.

Oh, wait, a Neo4j sales guy contacted me due to asking a question on the board, but when I mentioned my problem I never heard another word.

Not sure why they don't respond to questions but it has certainly changed my perception of them.

Yeah, It looks like we still need to write resolvers to manage some CRUD mutations.

As novices, we are probability asking something obvious, hence no response. Let's try luck and ask @lyonwj. I will let you know if I get any solution.

I felt the same - I read their docs and thought I had to be missing something obvious when no one responded.

Please (please) let me know if you get some resolution to this.

Based on your schema the, auto-generated mutation for creating the RATED relationship should be

AddUserRated(
from: _UserInput!
to: _MovieInput!
data: _RatedInput!
): _AddUserRatedPayload

so instead, your mutation should be

mutation {
  movie1: CreateMovie(title: "First Movie Title", year: 1998) {
    title
    year
  }
  user1: CreateUser(userId: "user1", name: "Gumby") {
    userId
    name
  }
  userrating1: AddUserRated(from: {userId: "user1"}, to: {title: "First Movie Title"}, data: {rating: 4.0, timestamp: 2020}) {
    rating
    timestamp
  }
}

Since there is no ID! field on the Movie type, instead the title field is treated as the id or primary-key type field.

I just tried this with your schema and seemed to work fine:

{
  "data": {
    "movie1": {
      "title": "First Movie Title",
      "year": 1998
    },
    "user1": {
      "userId": "user1",
      "name": "Gumby"
    },
    "userrating1": {
      "rating": 4,
      "timestamp": 2020
    }
  }
}

You can try running your query in GraphQL Playground (just open the GraphQL URL in a web browser) which will give you better error messages, auto-complete, as well as a way to inspect the schema to see what operations / arguments are available.

1 Like