Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Problem with relationships with properties #251

Closed
mayrmax opened this issue May 22, 2019 · 4 comments
Closed

Problem with relationships with properties #251

mayrmax opened this issue May 22, 2019 · 4 comments

Comments

@mayrmax
Copy link

mayrmax commented May 22, 2019

Hello,
first of all, thank you for this great library it really makes working with GraphQL a wonderful and easy thing.
I started to experiment with it a few days ago but got stuck on relationships with properties.

Schema GQL:

type Movie {
    id: ID!
    title: String
    overview: String
    poster: String
    datePublished: DateTime
    imdbRating: Float
    tmdbId: Int
    actionType: [UserAction]
}

type UserAction @relation(name: "USER_ACTION") {
    from: User!
    to: Movie!
    action: UserMediaAction
    created: DateTime
}

enum UserMediaAction {
    WATCHED
    WATCHLIST
    COLLECTED
}

type User {
    id: ID!
    actions: [UserAction]
}

GraphQL Query:

mutation {
      AddMovieActionType(from: {id: "e786b8ae-a958-430d-be61-f84dd2a9eae3"}, to: {id: "user-01"}, data: {action: WATCHED}) {
    action
      }
  }

Resulting Query (Debug output):

      MATCH (`user_from`:`User` {id: $from.id})
      MATCH (`movie_to`:`Movie` {id: $to.id})
      CREATE (`user_from`)-[`user_action_relation`:`USER_ACTION` {action:$data.action}]->(`movie_to`)
      RETURN `user_action_relation` { .action } AS `_AddMovieActionTypePayload`;
    
{
  "from": {
    "id": "e786b8ae-a958-430d-be61-f84dd2a9eae3"
  },
  "to": {
    "id": "user-01"
  },
  "data": {
    "action": "WATCHED"
  },
  "first": -1,
  "offset": 0
}

If I manually run the on neo4j it works as expected. Is there a problem with resolving nested variables? The $from.id part looks suspicious to me. And if so can somebody point me in the right direction so I can create a PR?

Best regards,
Max

@mayrmax
Copy link
Author

mayrmax commented May 31, 2019

I researched this topic further and it seems like this might be a problem on the driver side.
I think this could be solved using WITH by defining the passed objects and then accessing it as a normal map in cypher?

So the idea would be to create an entry like this for each passed parameter if its an object:
WITH {id: '...'} AS from

@johnymontana
Copy link
Member

Hey @mayrmax - are you getting an error when running this GraphQL mutation? Or is the graph just not updating as expected? If you're seeing an error could you add it here?

I think you might have the id fields mixed up in your mutation.

In the case of the AddMovieActionType mutation, the from argument should be the id of the user and the to argument should be the id of the movie, as defined in the type definition for UserAction:

type UserAction @relation(name: "USER_ACTION") {
    from: User!
    to: Movie!
    action: UserMediaAction
    created: DateTime
}

Could you give that a try and let us know if it works?

@mayrmax
Copy link
Author

mayrmax commented Jun 5, 2019

Hey, thanks for the reply. It's just not updating correctly.
I will give it a try and let you know!

Thanks

@mayrmax
Copy link
Author

mayrmax commented Jun 5, 2019

Well, it works I have no idea how I could miss that. Thank you very much!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants