prisma2_subscriptions icon indicating copy to clipboard operation
prisma2_subscriptions copied to clipboard

Prisma2 PubSub Example

Example subscriptions based off the prisma2 boilerplate and Ben Awad's video tutorial https://youtu.be/146AypcFvAU

How to use

yarn install
yarn start
-> open localhost:4000

1. Create User

mutation{
  signupUser(data: {
    email: "[email protected]",
    name: "Prisma Sub"
  }) {
    email
  }
}

2. Create New Post

mutation {
  createDraft(
    title: "Prisma Subscriptions", 
    content: "Subscriptions are working!"
    authorEmail: "[email protected]"
  ) {
    id,
    title,
    author {
      email
    }
  }
}
# {
#   "data": {
#     "createDraft": {
#       "id": "cjzvn2ckk0000sos951nxi6q1",
#       "title": "Prisma Subscriptions"
#     }
#   }
# }

3. Subscribe to Published Posts

subscription {
  publishedPost {
    title,
    content,
    published,
    author {
      email
    }
  }
}

OR filter by email

subscription(authorEmail: "[email protected]") {
  publishedPost {
    title,
    content,
    published,
    author {
      email
    }
  }
}

4. Publish Draft Post (From Step 2)

# Make sure to use id from step 2
mutation {
  publish(
    id: "cjzvn2ckk0000sos951nxi6q1"
  ) {
    id,
    title
  }
}
# {
#   "data": {
#     "publish": {
#       "id": "cjzvn2ckk0000sos951nxi6q1",
#       "title": "Prisma Subscriptions"
#     }
#   }
# }

5. See the results in your subscription!!!

# {
#   "data": {
#     "publishedPost": {
#       "title": "Prisma Subscriptions",
#       "content": "Subscriptions are working!",
#       "published": true,
#       "author": {
#         "email": "[email protected]"
#       }
#     }
#   }
# }

Are your subscriptions returning "data": null ?

This might help https://github.com/prisma/prisma2/issues/454