Thanks to doeke for reporting this bug here: https://www.graph.cool/forum/t/1-0-self-relation-with-reverse-field-errors/2066?u=nilan
Cannot get self-relation with reverse field working.
type DataRow @model {
id: ID! @unique
mergedInto: DataRow
mergedFrom: [DataRow!]!
}
Deploy:
DataRow
ร The relation field `mergedInto` must specify a `@relation` directive: `@relation(name: "MyRelation")`
ร The relation field `mergedFrom` must specify a `@relation` directive: `@relation(name: "MyRelation")`
Next I tried with relation directive specified
type DataRow @model {
id: ID! @unique
mergedInto: DataRow @relation(name: "MergeRelation")
mergedFrom: [DataRow!]! @relation(name: "MergeRelation")
}
Deploy:
DataRow
ร A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'MergeRelation'
ร A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'MergeRelation'
What does work is if I leave out the reverse field:
type DataRow @model {
id: ID! @unique
mergedInto: DataRow
}
I'm having the same issue. My schema causing it is:
type User {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
email: String! @unique
followers: [User!]! @relation(name: "Following")
follows: [User!]! @relation(name: "Following")
}
resulting in error:
Deploying service `XXXXX` to stage `dev` on cluster `local`... 29ms
Errors:
User
โ A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'Following'
โ A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'Following'
The issue is still in Prisma and is unfortunately blocking my migration from Graphcool 0.x. Can't wait to be able to get Prisma to work :)
Yes, this is supposed to be fixed in 1.0.11. Do you have a reproduction?
I just tried to deploy this datamodel:
type User {
id: ID! @unique
name: String!
}
type DataRow {
id: ID! @unique
mergedInto: DataRow @relation(name: "MergeRelation")
mergedFrom: [DataRow!]! @relation(name: "MergeRelation")
}
It was successfully deployed to prisma-us1 and local. You might need to run prisma local upgrade to pull the latest Docker image ๐
@marktani:
To go futher from the @pie6k exemple, is this wrong?
type User {
id: ID! @unique
email: String! @unique
...
follwers: [User!]! @relation(name: "UsersFollowers")
following: [User!]! @relation(name: "UsersFollowing")
}
This is now fixed in the latest release.
@johannpinson I am not sure what you mean exactly, can you elaborate your question? ๐
In my own schema, to avoid 2 relation with the same name like "UserFollows", I add two different name for the self-relation (so "UserFollowers" and "UserFollowing").
I would like to know if it's a bad idea?
Both approaches result in different data models ๐ Which one is the better choice in a concrete context is better discussed in a new question in the Forum.
Most helpful comment
The issue is still in Prisma and is unfortunately blocking my migration from Graphcool 0.x. Can't wait to be able to get Prisma to work :)