Prisma1: Prisma subscriptions example

Created on 17 Jan 2018  ยท  11Comments  ยท  Source: prisma/prisma1

Current behavior

Firing a mutation in the subscriptions example throws the error: [Network error]: FetchError: request to http://localhost:60000/subscriptions/dev failed, reason: connect ECONNREFUSED 127.0.0.1:60000

Changing the Prisma endpoint being supplied to graphql-yoga to 'http://localhost:4466/subscriptions/test' resolves this error.

Without any errors, listening on the publications subscription and firing writePost doesn't trigger any subscription events.

bu2-confirmed aredocs

Most helpful comment

Hey @hoodsy and @daver182, thanks a lot for your help with this. I could single out the problem, fixed the subscription example for now, and created a new bug report here: https://github.com/graphcool/prisma/issues/1734

It seems that subscriptions don't always work when where is used.

@hoodsy you should be able to confirm this by changing your subscription resolver to

// in resolvers/index.js
  Subscription: {
    message: {
      subscribe: async (parent, args, ctx, info) => {
        return ctx.db.subscription.message({ }, info)
      },
    },

Please follow the discussion in the new issue, thanks ๐Ÿ™Œ

All 11 comments

Hey @hoodsy, thanks a lot for your feedback!
This is a problem with the hardcoded endpoint here (in src/index.js):

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

Could you please replace that with

endpoint: 'http://localhost:4466/subscriptions/test'

Clearly the README should be adjusted accordingly ๐Ÿ™‚

The graphql-yoga/subscriptions example has a working implementation using PubSub: https://github.com/graphcool/graphql-yoga/tree/master/examples/subscriptions

Yesterday we released a new minor version that fixed a specific bug with subscriptions, could you try upgrading? :slightly_smiling_face: npm install - g prisma prisma local upgrade

Thanks for the heads up โ€“ I've upgraded, but am still getting the same results. Message subscription is active, but creating a Message doesn't trigger the subscription:

Subscription

subscription ($_where: MessageSubscriptionWhereInput) {
  message(where: $_where) {
    node {
      text
      sender {
        id
        name
      }
    }
  }
}
variables:
{
  "_where": {
    "mutation_in": [
      "CREATED",
      "UPDATED"
    ]
  }
}

Mutation

mutation ($data: MessageCreateInput!) {
  createMessage(data: $data) {
    id
    text
    sender {
      id
      name
      __typename
    }
    __typename
  }
}
operationName: null
variables:
{
  "data": {
    "text": "test"
  }
}

Same goes for the prisma/examples/subscriptions example... At the same time, the graphql-yoga/subscriptions example works, but doesn't depend on Type subscriptions. This is the only bit of subscription code I've been able to get running

I'm getting the same results, the subscription works but only when using the prisma endpoint, not with the node app. The response from the server is ok but I don't get any update, I've tested with the example and all the tools on the latest version

A recent change in prisma-binding might be related, could you try it with version 1.4.0 again, @hoodsy @daver182? ๐Ÿ™‚

The authorization token was not passed into the subscription link.

In the playground, where subscriptions work, I am required to use the subscription message:

subscription {
  message {
       node {
         id
         text
       }
     }
  }

In my app, the message subscription throws an error, and requires I use messages, but doesn't pick up any newly created messages.

@hoodsy, can you share more information about this?

What is the error you receive when using message? How are you setting up the message subscription in your code? How does your schema.graphql look like?

I've realized the error with message is schema related โ€“ with all naming aligned and no errors, I don't have subscriptions coming through in app (but do in playground with same query):

# in UI
const MESSAGES_SUBSCRIPTION = gql`
  subscription message {
    message {
      node {
        text
        sender {
          id
          name
        }
      }
    }
  }
`
// in resolvers/index.js
  Subscription: {
    message: {
      subscribe: async (parent, args, ctx, info) => {
        return ctx.db.subscription.message({
            where: {
              mutation_in: ['CREATED', 'UPDATED'],
            },
          }, info)
      },
    },
# in schema.graphql
type Subscription {
  message: MessageSubscriptionPayload
}

I think it's worth noting that my resolver function never gets triggered โ€“ย I've tested with console.log

@marktani no, it's not that, I've tried with the example

Hey @hoodsy and @daver182, thanks a lot for your help with this. I could single out the problem, fixed the subscription example for now, and created a new bug report here: https://github.com/graphcool/prisma/issues/1734

It seems that subscriptions don't always work when where is used.

@hoodsy you should be able to confirm this by changing your subscription resolver to

// in resolvers/index.js
  Subscription: {
    message: {
      subscribe: async (parent, args, ctx, info) => {
        return ctx.db.subscription.message({ }, info)
      },
    },

Please follow the discussion in the new issue, thanks ๐Ÿ™Œ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marktani picture marktani  ยท  3Comments

jannone picture jannone  ยท  3Comments

ragnorc picture ragnorc  ยท  3Comments

hoodsy picture hoodsy  ยท  3Comments

nikolasburk picture nikolasburk  ยท  3Comments