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

access properties of relations? #97

Closed
stephen-dahl opened this issue Aug 28, 2018 · 1 comment
Closed

access properties of relations? #97

stephen-dahl opened this issue Aug 28, 2018 · 1 comment

Comments

@stephen-dahl
Copy link

stephen-dahl commented Aug 28, 2018

given the schema
(Cart) --[hasItem]->(Item)
how would you get the quantity property from the relation hasItem?

type Cart {
    items: [Item]
    ...
}
type Item {
    name: String!
    description: String!
    price: Float!
    ...
}
type hasItem {
   quantity: Int!
}
@johnymontana
Copy link
Contributor

Hey @stephen-dahl we've recently added better relationship type support in v1.0.x. For your example, try

type Cart {
  items: [CartItems]
  
}

type Item {
  name: String!
  description: String!
  price: Float!
}

type CartItems @relation(name:"HAS_ITEM") {
  from: Cart
  to: Item
  quantity: Int!
}

If you contruct your schema using makeAugmentedSchema (or augmentSchema) you'll see autogenerated Query and Mutation types for basic CRUD. In your case to access quantity your GraphQL query would look something like:

Cart {
  items {
    quantity
    Item {
      name
      description
     }
  }
}

Please give it a try and let us know how it works!

See the docs on this here: https://grandstack.io/docs/neo4j-graphql-js.html#relationship-types

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