Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Updates Subscriptions Example #1635

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/1.0/subscriptions/.graphqlconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ projects:
endpoints:
default: "http://localhost:4000"
database:
schemaPath: "src/generated/graphcool.graphql"
schemaPath: "src/generated/prisma.graphql"
extensions:
graphcool: database/graphcool.yml
prisma: database/prisma.yml
2 changes: 1 addition & 1 deletion examples/1.0/subscriptions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```
yarn
yarn graphcool deploy
yarn prisma deploy
yarn start
```

Expand Down
11 changes: 8 additions & 3 deletions examples/1.0/subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
"name": "subscriptions",
"scripts": {
"start": "NODE_ENV=dev node src/index.js",
"graphcool": "graphcool",
"prisma": "prisma",
"playground": "graphcool playground"
},
"dependencies": {
"graphcool-binding": "1.3.3",
"prisma-binding": "1.3.7",
"graphql-yoga": "1.1.4"
},
"devDependencies": {
"graphcool": "1.0.0-beta4.0.6"
"prisma-cli": "beta"
},
"prettier": {
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# THIS FILE HAS BEEN AUTO-GENERATED BY THE "GRAPHCOOL DEPLOY"
# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
# DO NOT EDIT THIS FILE DIRECTLY

#
Expand Down
70 changes: 42 additions & 28 deletions examples/1.0/subscriptions/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { GraphQLServer } = require('graphql-yoga')
const { Graphcool } = require('graphcool-binding')
const { Prisma } = require('prisma-binding')

const resolvers = {
Query: {
Expand All @@ -9,12 +9,16 @@ const resolvers = {
},
Mutation: {
writePost(parent, { title, text, isPublished }, ctx, info) {
return ctx.db.mutation.createPost({ data: {
title,
text,
isPublished,
}
}, info)
return ctx.db.mutation.createPost(
{
data: {
title,
text,
isPublished,
},
},
info,
)
},
// writeComment(parent, { body, postId }, ctx, info) {
// return ctx.db.mutation.writeComment({ data: {
Expand All @@ -28,41 +32,51 @@ const resolvers = {
},
Subscription: {
publications: {
subscribe: async(parent, args, ctx, info) => {
return ctx.db.subscription.post({ where: {
mutation_in: ["CREATED", "UPDATED"],
node: {
isPublished: true
}
}}, info)
subscribe: async (parent, args, ctx, info) => {
return ctx.db.subscription.post(
{
where: {
mutation_in: ['CREATED', 'UPDATED'],
node: {
isPublished: true,
},
},
},
info,
)
},
},
comments: {
subscribe: async(parent, args, ctx, info) => {
return ctx.db.subscription.comments({ where: {
node: {
post: {
title_contains: "News"
}
}
}}, info)
}
}
}
subscribe: async (parent, args, ctx, info) => {
return ctx.db.subscription.comments(
{
where: {
node: {
post: {
title_contains: 'News',
},
},
},
},
info,
)
},
},
},
}

const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Graphcool({
typeDefs: 'src/generated/graphcool.graphql',
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: 'http://localhost:60000/subscriptions/dev',
secret: 'mysecret123',
}),
debug: true,
}),
})

server.start(() => console.log('Server is running on http://localhost:4000'))
server.start(({ port }) => console.log(`Server is running on http://localhost:${port}`))
4 changes: 2 additions & 2 deletions examples/1.0/subscriptions/src/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# import Post, PostSubscriptionPayload from "./generated/graphcool.graphql"
# import Post, PostSubscriptionPayload from "./generated/prisma.graphql"

# you need to activate this later: # import Comment, CommentSubscriptionPayload from "./generated/graphcool.graphql"
# you need to activate this later: # import Comment, CommentSubscriptionPayload from "./generated/prisma.graphql"

type Query {
feed: [Post!]!
Expand Down
Loading