Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription issue #229

Closed
revskill10 opened this issue Aug 15, 2018 · 19 comments
Closed

Subscription issue #229

revskill10 opened this issue Aug 15, 2018 · 19 comments

Comments

@revskill10
Copy link

revskill10 commented Aug 15, 2018

I'm following tutorial at howtographql.com, here's my subscription for newLink:

function newLinkSubscribe (parent, args, context, info) {
  return context.db.subscription.link(
    { where: { mutation_in: ['CREATED'] } },
    info,
  )
}

const newLink = {
  subscribe: newLinkSubscribe
}

module.exports = {
  newLink,
}

My subscription query is:

subscription RealTimeFeed {
    newLink {
      mutation
      node{
        url
      }
    }
  }

But when i post a mutation to create new link

mutation {
  post(
    url: "fdsfdsdsdf.graphqlweesfsdfkly.com"
    description: "Curated GraphQL content coming to your email inbox every Friday"
  ) {
    id
  }
}

, i got error :

{
  "error": {
    "name": "TypeError",
    "message": "Cannot read property 'link' of undefined"
  }
}

But if i go to database, schema, i got correct subscription:

{
  "data": {
    "link": {
      "mutation": "CREATED",
      "node": {
        "url": "fdsfdsdsdf.graphqlweesfsdfkly.com"
      }
    }
  }
}

This is killing me hardly. Any magic for subscription only work for database, but not on app ?.

My schema.graphql is:

# import Link, LinkSubscriptionPayload  from "./src/generated/prisma.graphql"

type Query {
  info: String!
  feed: [Link!]!

  # Fetch a single link by its `id`
  link(id: ID!): Link
  user: User
}

type Mutation {
  post(url: String!, description: String!): Link!
  signup(email: String!, password: String!, name: String!): AuthPayload
  signinUser(email: String!, password: String!): AuthPayload
}

type AuthPayload {
  token: String
  user: User
}

type User {
  id: ID!
  name: String!
  email: String!
  links: [Link!]!
}

type Subscription {
  newLink: LinkSubscriptionPayload
}

My package.json:

{
  "name": "hackernews-node",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "graphql-yoga": "^1.16.0",
    "jsonwebtoken": "^8.3.0",
    "prisma-binding": "^2.1.4"
  }
}
@joefru
Copy link

joefru commented Aug 15, 2018

Had the same issue when upgrading prisma-binding to 2.1.4. I suspect a bug there. When I downgrade to prisma-binding@2.1.3 the problem goes away.

@revskill10
Copy link
Author

@joefru I got same problem even with 2.1.3, weird.

@maury91
Copy link

maury91 commented Aug 17, 2018

Related: howtographql/howtographql#758

@maury91
Copy link

maury91 commented Aug 17, 2018

Same for me, downgrading to 2.1.3 solved the issue

@maury91
Copy link

maury91 commented Aug 17, 2018

The error is in this line:

https://github.com/graphql-binding/graphql-binding/blob/master/src/Delegate.ts#L88

I changed from

const data = { [info.fieldName]: value.data[fieldName] }

to

const data = { [info.fieldName]: value[fieldName] }

and it solved the error, but this raises the question. Should the value pass to Delegate contain a field named data?

Because if the answer is yes, then the error is on the part of the code where we are not wrapping that object in ".data"

@revskill10
Copy link
Author

Thanks for your suggestions. Finally i decided to move to ApolloServer, i couldn't stand a broken library for each upgrade, so hurt :(

@maury91
Copy link

maury91 commented Aug 17, 2018

The issue still exists, leave it open until is fixed in the next version

@revskill10 revskill10 reopened this Aug 17, 2018
@revskill10
Copy link
Author

revskill10 commented Aug 17, 2018

@maury91 I reopened the issue for who's interested. There're some serious issues here and there.
Basically, the only way to make all these issues less hurt for developers to upgrade deps, is to rewrite the tutorial following TDD, make library for test so that we could write clean test before any coding.
It saves time as well as gives more helpful debugging stories to fix them.

@joealden
Copy link

@schickling @timsuchanek this issue is blocking me from updating. Would love to see it fixed.

@ntziolis
Copy link

ntziolis commented Aug 19, 2018

Same here, in fact it cost me about 8h yesterday while I was debugging using fragments with subscriptions (which then resulted in another bug raised). I agree with other devs that the continuous introductions of major bugs like non working subscriptions is something to worry about. Can we assist you in any way setting up better regression testing?

In addition its a terrible experience for first time graphql'ers when they use the yoga boilerplates and right away it doesn't work.

@revskill10
Copy link
Author

One note: I added a PR here: graphql-boilerplates/node-graphql-server#374 .

@SilencerWeb
Copy link

SilencerWeb commented Aug 20, 2018

@revskill10 maybe it would be better to make a pull request with a fix as suggested @maury91? Btw, I faced the same problem recently and spent about a week to solve it, downgrading prisma-binding to 2.3.1 solved problem for me. But note this - prisma/prisma#2920 (comment)

@ntziolis
Copy link

ntziolis commented Aug 20, 2018

@maury91 I can confirm that making the changes suggested fixes the issue. Can you submit a pull request?

@maury91
Copy link

maury91 commented Aug 20, 2018

@ntziolis @SilencerWeb the main problem is that the issue is on another repository ( https://github.com/graphql-binding/graphql-binding ), and we don't know if consumers that are not prisma-binding are affected, by making that change we can potentially break another consumer, so is worth first investigating if that is the expected behaviour and is prisma-binding the one passing the wrong parameters to Delegate, or if it is the opposite and proceed with the fix.

@ntziolis
Copy link

ntziolis commented Aug 20, 2018

@maury91 I see, lmk if I can assist in any way. We need this current version of the bindings as its the first one to allow fragments in subscriptions (prisma/prisma#2026). Have been waiting for that fix for a long time as it will significantly clean up our code based and reduce errors of devs by not keeping fragment in subscription in sync.

@etx
Copy link

etx commented Aug 21, 2018

Same problem here. 2.1.3 my subs work but when moving to 2.1.4 they error out

(node:4867) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'section' of undefined at Object.<anonymous> (/path/node_modules/graphql-binding/dist/Delegate.js:88:105) at step (/path/node_modules/graphql-binding/dist/Delegate.js:32:23) at Object.next (/path/node_modules/graphql-binding/dist/Delegate.js:13:53) at fulfilled (/path/node_modules/graphql-binding/dist/Delegate.js:4:58) at <anonymous> at process._tickCallback (internal/process/next_tick.js:160:7) (node:4867) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwinginside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:4867) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@simonjoom
Copy link

simonjoom commented Aug 28, 2018

Maury91 well found the issue of this problem:
#229 (comment)

This worked well for me to

@divyenduz
Copy link
Contributor

divyenduz commented Aug 28, 2018

This is fixed in prisma-binding 2.1.5 🎉

@akashanand708
Copy link

downgrading to 2.1.3 solved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants