-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
field projection for explicit many-to-many relations #1023
Comments
well, i gave it another shot and tried field projections for implicit and explicit relations again.
# implicit relation
model ImplicitA {
id String @id @default(uuid())
name String
implicitBs ImplicitB[]
}
model ImplicitB {
id String @id @default(uuid())
name String
implicitAs ImplicitA[]
}
# explicit relation
model ExplicitA {
id String @id @default(uuid())
name String
explicitBs ExplicitAToExplicitB[]
}
model ExplicitB {
id String @id @default(uuid())
name String
explicitAs ExplicitAToExplicitB[]
}
model ExplicitAToExplicitB {
explicitA ExplicitA @relation(fields: [explicitAId], references: [id])
explicitAId String
explicitB ExplicitB @relation(fields: [explicitBId], references: [id])
explicitBId String
@@id([explicitAId, explicitBId])
} my models: // implicit relation
const implicitA = objectType({
name: 'ImplicitA',
definition(t) {
t.model.id()
t.model.name()
t.model.implicitBs()
}
})
const implicitB = objectType({
name: 'ImplicitB',
definition(t) {
t.model.id()
t.model.name()
t.model.implicitAs()
}
})
// explicit relation
const explicitA = objectType({
name: 'ExplicitA',
definition(t) {
t.model.id()
t.model.name()
t.model.explicitBs()
}
})
const explicitB = objectType({
name: 'ExplicitB',
definition(t) {
t.model.id()
t.model.name()
t.model.explicitAs()
}
})
const explicitAToExplicitB = objectType({
name: 'ExplicitAToExplicitB',
definition(t) {
t.model.explicitA()
t.model.explicitB()
}
}) and my queries: // implicit relation
const implicitA = extendType({
type: 'Query',
definition(t) {
t.crud.implicitA()
t.crud.implicitAs()
}
})
const implicitB = extendType({
type: 'Query',
definition(t) {
t.crud.implicitB()
t.crud.implicitBs()
}
})
// explicit relation
const explicitA = extendType({
type: 'Query',
definition(t) {
t.crud.explicitA()
t.crud.explicitAs()
}
})
const explicitB = extendType({
type: 'Query',
definition(t) {
t.crud.explicitB()
t.crud.explicitBs()
}
}) this way i can send the following queries to the graphql api: query ImplicitAs {
name
explicitBs {
name
}
}
query ExplicitAs {
name
explicitBs {
explicitB {
name
}
}
} i tried to override the what's also not clear is how can i order (and maybe filter) the related nodes with these field projections. pagination is there by default as i can send another great feature would be adding some metadata to the explicit relation, for example the number of nodes. this is probably offtopic here because the batch read of |
Any updates on this? Or will be resolved in |
@RomanTsegelskyi sorry for the late reply, this project is dead as per #1039. you can find the new plugin here: n:n relations are in the midterm while crud operations are in the longterm goals. initially they estimated the new plugin end of q1/early q2 but tbh i wouldn't expect these features to be done this year. |
is there an easy way to add a field projection for an explicit many-to-many relation while hiding the relation table from the graphql schema?
schema.prisma
:for this specific use case (not too many roles) i'd like to see this at the end:
graphql.schema
:first i tried to simply add the
roles
field projection to myUser
model but it was missing theUserToRole
model so it did not work:as i didn't want to reveal that relation in the graphql api i solved it by adding a custom field to the
User
model but i'm not sure this is the best way to add this data, especially because i have to add something similar to the other end of the relationship (to theusers
field of theRole
model) which is repetitive in the long run with many relations:while this solves the problem temporarily it doesn't seem like the best idea when i have a lot of data. and i still have to figure out how to reuse and add the auto-generated query arguments as field arguments here to have a schema like this:
what's the best way to do this?
The text was updated successfully, but these errors were encountered: