Подписки Graphql не отображают новые дополнения к базе данных
Я следую этому уроку. Мой полный код здесь.
Многие люди говорят, что подписка не работает. Я не знаю причину этого. Я думаю проблема в том { where: { mutation_in: ['CREATED'] } }
в Subscription.js
Subscription.js
const newLink = {
subscribe: (parent, args, ctx, info) => {
return ctx.db.subscription.link(
{ where: { mutation_in: ['CREATED'] } },
info,
)
},
}
const newVote = {
subscribe: (parent, args, ctx, info) => {
return ctx.db.subscription.vote(
{ where: { mutation_in: ['CREATED'] } },
info,
)
},
}
module.exports = {
newLink,
newVote,
}
index.js
const { GraphQLServer } = require('graphql-yoga')
const { Prisma } = require('prisma-binding')
const Query = require('./resolvers/Query')
const Mutation = require('./resolvers/Mutation')
const Subscription = require('./resolvers/Subscription')
const resolvers = {
Query,
Mutation,
Subscription
}
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: "https://us1.prisma.sh/public-surfape-281/hackernews-graphql-js/dev",
secret: 'mysecret123',
}),
}),
})
server.start(() => console.log('Server is running on http://localhost:4000'))
schema.graphql
# import Link, Vote, LinkSubscriptionPayload, VoteSubscriptionPayload from './generated/prisma.graphql'
type Query {
feed(filter: String, skip: Int, first: Int): [Link!]!
}
type Mutation {
post(url: String!, description: String!): Link!
signup(email: String!, password: String!, name: String!): AuthPayload
login(email:String!, password:String!):AuthPayload
}
type AuthPayload {
token: String
user: User
}
type Subscription{
newLink:LinkSubscriptionPayload
newVote:VoteSubscriptionPayload
}