tfiwm
01/21/2018, 11:55 AMtfiwm
01/21/2018, 12:08 PMtypescript
import { GraphQLServer, PubSub } from 'graphql-yoga';
import { Prisma } from './generated/prisma';
import resolvers from './resolvers';
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
endpoint: process.env.PRISMA_ENDPOINT, // the endpoint of the Prisma DB service (value is set in .env)
secret: process.env.PRISMA_SECRET, // taken from database/prisma.yml (value is set in .env)
debug: true // log all GraphQL queries & mutations
}),
pubsub: new PubSub()
})
});
server.start(() => console.log(`Server is running on <http://localhost:4000`>));
donβt forget to extend your Context Interface π
after that u have access in your resolver to the pubsub under ctx.pubsub
Works so cool everything :))tfiwm
01/21/2018, 12:33 PMdivyendu
01/21/2018, 1:08 PMdivyendu
01/21/2018, 1:09 PMtfiwm
01/21/2018, 1:13 PMtfiwm
01/21/2018, 1:13 PMdivyendu
01/21/2018, 1:14 PMtfiwm
01/21/2018, 1:14 PMtfiwm
01/21/2018, 1:15 PMtfiwm
01/21/2018, 1:15 PMtfiwm
01/21/2018, 1:17 PMjavascript
this.subscriptionServer = SubscriptionServer.create(
{
schema: this.executableSchema,
execute,
subscribe,
onOperation: async (message, connection, webSocket) => {
let context
try {
context =
typeof this.context === 'function'
? await this.context({ connection })
: this.context
} catch (e) {
console.error(e)
throw e
}
return { ...connection, context }
},
},
{
server: combinedServer,
path: this.options.subscriptions,
},
)
tfiwm
01/21/2018, 1:17 PMtfiwm
01/21/2018, 1:18 PMtfiwm
01/21/2018, 1:18 PMdivyendu
01/21/2018, 1:22 PMtfiwm
01/21/2018, 1:47 PMtfiwm
01/21/2018, 1:47 PMtfiwm
01/21/2018, 2:00 PM