Retrieve Relationship Properties in a Type query

Hello -

I'm trying to track a relationship between two entities (a review and a tag) with a strength and then be able to easily return all the tags for a review along with their strength. So I currently have:

type Review {
  id: ID!
  stars: Int
  stars_value: Int 
  text: String
  date: DateTime
  user: User @relation(name: "WROTE", direction: "IN")
  tags: [Tagged]
}

type Tag {
  id: ID!
  name: String
  reviews: [Tagged]
}

type Tagged @relation(name: "TAGGED") {
  from: Review
  to: Tag 
  strength: Int
}

When I pull up a Review(or add a new Review), I need to be able see/set each of the tags with their strength. Can't seem to figure out how to ask for strength though. Hopefully I'm missing something easy!

This works fine for returning all reviews with their tags:

{
  Spirit {
    name
    tags {
      name
    }
  }
}

Would appreciate any suggestions or guidance! Or if someone thinks there is a better way to represent this data!

Thanks.

Hi @cknisley44 -

In this case the strength property is on the relationship and the tag name is on the Tag node. So the GraphQL query to retrieve both the strength and name of the tag, starting from a review, should look like this:

{
  Review(first:1) {
    tags {
      strength
      Tag {
        name
      }
    }
  }
}

The relationship type query api uses the type name, instead of from/to. You can read more about relationship types here: https://grandstack.io/docs/graphql-relationship-types.html

1 Like