-
Notifications
You must be signed in to change notification settings - Fork 275
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
Subscription type checking error with Prisma $subscribe #86
Comments
Hey there, the problem here is related to |
@Weakky I don't use |
Yes, but I assume you haven't defined The error |
@Devlin556, @Weakky: Indeed, I made it work in one of my project.
Here is an example: // ...
const ReactionSubscriptionWhereInput = prismaInputObjectType({
name: "ReactionSubscriptionWhereInput",
definition(t) {
t.prismaFields(["*"])
}
})
const ReactionPreviousValues = prismaObjectType({
name: "ReactionPreviousValues",
definition(t) {
t.prismaFields(["*"])
}
})
const MutationType = prismaEnumType({
name: "MutationType",
members: ["CREATED", "UPDATED", "DELETED"]
})
const ReactionSubscriptionPayload = objectType({
name: "ReactionSubscriptionPayload",
definition(t) {
t.field("mutation", {
type: "MutationType",
resolve: ({ mutation }) => mutation
})
t.field("node", {
type: "Reaction",
resolve: ({ node }) => node
})
t.string("updatedFields", {
list: true,
resolve: ({ updatedFields }) => updatedFields
})
t.field("previousValues", {
type: "ReactionPreviousValues",
resolve: ({ previousValues }) => previousValues
})
}
})
const ReactionSub = subscriptionField("reaction", {
type: "ReactionSubscriptionPayload",
args: {
where: arg({ type: "ReactionSubscriptionWhereInput" })
},
subscribe: (parent, { where }, context) => {
return context.prisma.$subscribe.reaction(where)
},
resolve: payload => {
return payload
}
})
// ... |
Hey there, I just released I made a small guide here: https://github.com/prisma/nexus-prisma/releases/tag/v0.3.7 @gauthierrodaro @Devlin556 It should remove the need for you to redeclare all the subscription types. The code below is now enough for things to work 🙏 export const SubscriptionUser = subscriptionField('users', {
type: 'UserSubscriptionPayload',
subscribe(root, args, ctx) {
return ctx.prisma.$subscribe.user() as any
},
resolve(payload) {
return payload
},
}) |
@Weakky The |
I tried to follow your guide, but there is a compilation error
Do I need to redefine
|
Oh sorry my mistake, I don't have to redefine |
Hey, @Weakky I tried your solution but it isn't working. Unfortunately, I don't get any type with Edit: So on Prisma's Slack, I got the answer that Subscriptions aren't yet implemented in Prisma2's Photon 😭 |
Closing for lack of activity. |
Hi everyone! Yesterday I’ve implemented the subscription in my project using nexus/nexus-prisma. By default, function call
prisma.$subscribe.type()
returns asyncIterator which resolves as{node: Type, mutation: MutationType, updatedFields: [String], previousValue: TypePreviousValue}
and this structure is convenient for my case. But if I use this asyncIterator in my subscription - nexus throws an error for the subscription in Playground, which says:Unknown prisma-client function for field TypeSubscriptionPayload.mutation
, but inresolve
function it's a normal object with normal values. Any ideas? Apollo server works fine it this case and I think that this problem related to the implementation of subscription on Nexus.Packages versions:
nexus-prisma: 0.3.5
nexus: 0.11.3
The text was updated successfully, but these errors were encountered: