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

Reflexive relation types, fixes for #113 and #124 #125

Merged
merged 15 commits into from
Oct 10, 2018
Merged

Reflexive relation types, fixes for #113 and #124 #125

merged 15 commits into from
Oct 10, 2018

Conversation

michaeldgraham
Copy link
Collaborator

@michaeldgraham michaeldgraham commented Oct 10, 2018

Fixes

Features:

Reflexive Relation API

The following FriendOf relation type is reflexive in the sense that it comes from and goes to the same type. There is now support in the generated Query and Mutation API for reflexive relation types.

type User implements Person {
  ...
  rated(rating: Int): [Rated]
  friends(since: Int): [FriendOf]
}

# Reflexive relation type
type FriendOf {
  from: User
  since: Int
  to: User
}

type Rated {
  from: User
  rating: Int
  to: Movie
}

Given the above SDL format (what you write), the following SDL is generated as a result of the schema augmentation process (augmentSchema or makeAugmentedSchema). The since argument on the friends is distributed over the directed fields, from and to.

type User implements Person {
  userId: ID!
  name: String
  rated(rating: Int): [_UserRated]
  friends: _UserFriendsDirections
}

type _UserFriendsDirections {
  from(since: Int): [_UserFriends]
  to(since: Int): [_UserFriends]
}

type _UserFriends {
  since: Int
  User: User
}

This results in support for the following selection set format:

User {
  userId
  name
  friends {
    from(since: 1) {
      since
      User {
        name
      }
    }
    to(since: 2) {
      since
      User {
        name
      }
    }
  }
}

Tests

The following tests have been added in cypherTest.js for the reflexive relation type API:

  • Add relationship mutation with relationship property (reflexive)
  • Remove relationship mutation (reflexive)
  • query reflexive relation nested in non-reflexive relation
  • query non-reflexive relation nested in reflexive relation
  • query relation type with argument
  • query reflexive relation type with arguments

Other

This PR also introduces a new translate.js file, from which helpers are exported and used in index.js, refactoring the recursive GraphQL to Cypher translation process.

@johnymontana johnymontana merged commit aa038eb into neo4j-graphql:master Oct 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants