I saw a document about how to make self relational model for follow/unfollow but I’m unable to understand that. I have tried. But I can’t complete it. Below my code:
type User @model{
id: ID!
userId: String!
username: String!
email: String!
email_verified: Boolean!
follower: [UserLink]! @hasMany
following:[UserLink]! @hasMany(indexName: "followingUser")
}
type UserLink @model{
creator: User!
follower: User!
}
Hi @Asit_Dixit and welcome!
The @model
and @hasMany
are not directives that our API understands. Are you coming from AWS Amplify?
Fauna’s GraphQL API uses particular @
directives to define things like relationships, indexes, user-defined functions, etc. You can check out our documentation here: GraphQL directives - Fauna Documentation
If you are just getting started with GraphQL and Fauna, then I also recommend going through our GraphQL Quickstart and following up with the tutorials: GraphQL tutorials - Fauna Documentation
We also have a short article on how to create a self-referential model. For your schema, creating a many-to-many connection between a type and itself might look something like this
type User {
id: ID!
userId: String!
username: String!
email: String!
email_verified: Boolean!
follower: [UserLink]! @relation(name: "creator")
following:[UserLink]! @relation(name: "follower")
}
type UserLink {
creator: User! @relation(name: "creator")
follower: User! @relation(name: "follower")
}
Hi @Asit_Dixit do you still need help with your GraphQL schema for Fauna?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.