Declares that the current field has a bi-directional relationship with the target type.




Argument Type Required Description




The name for the relation. Must contain only characters in the set [a-zA-Z0-9_].


The @relation directive marks the annotated field as participating in a bi-directional relationship with the target type.

The name argument defines the name of the relationship, and is useful if there is any ambiguity in relationship construction. For example, if the target type has two fields referring to the source type. The name argument must be unique. The same name should be used in both types participating in the relationship.

For more information, see the relations reference.


type User {
  name: String!
  posts: [Post!] @relation(name: "user_posts")
  reviews: [Post!] @relation(name: "user_reviews")

type Post {
  title: String!
  author: User! @relation(name: "user_posts")
  reviewers: [User!] @relation(name: "user_reviews")

User documents are related to Post documents, and vice-versa. Since both types contain references to the peer type, each distinct relationship has a distinct name.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!