Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

subscribeToMore: GraphQL subscription error (cannot read property 'then' of undefined) #277

Closed
muhammad-abubakkar opened this issue Sep 21, 2017 · 14 comments

Comments

@muhammad-abubakkar
Copy link

apollo-client: 1.9.2
apollo-angular: 0.13.1
subscriptions-transport-ws: 0.8.3
angular: 4.4.3

@groundmuffin
Copy link

try to stay on graphql-js ^0.10.0

@shtse8
Copy link

shtse8 commented Oct 25, 2017

I have the same issue, any updates?

1 similar comment
@osmanperviz
Copy link

I have the same issue, any updates?

@AkimaLunar
Copy link

I am getting {type: "error", id: "1", payload: {message: "Cannot read property 'then' of undefined"}} error on subscription. What's the best way to debug? Where to look?

@gHashTag
Copy link

gHashTag commented Dec 5, 2017

I'm Installed "graphql": "^0.10.5" and worked for me

@ianmartorell
Copy link
Contributor

This was fixed with #261

mxstbr added a commit to withspectrum/spectrum that referenced this issue Jan 30, 2018
This fixes the "Cannot read property 'then' of undefined" error we've
been getting in prod constantly. Ref issue: apollographql/subscriptions-transport-ws#277

Fixes #2305, fixes #2310
@jcteague
Copy link

jcteague commented Mar 2, 2018

Has the fixed been released? I had this problem. Had to downgrade to graphql 0.10.5

@ianmartorell
Copy link
Contributor

Yeah, upgrading to the latest version resolved it for me at the time.

@jcteague
Copy link

jcteague commented Mar 2, 2018

Hmmm... I must have some version conflicts going on.

"apollo-cache-inmemory": "^1.1.9",
 "apollo-client": "^2.0.4",
 "apollo-link-http": "^1.5.2",
 "apollo-link-ws": "^1.0.7",
 "graphql": "^0.10.5",  //this works, 0.11 got error
 "graphql-subscriptions": "^0.5.8",
 "subscriptions-transport-ws": "^0.9.0",

with graphql 0.11 I was gettting this error message, moving to 0.10.5 seemed to have worked (still testing)

@ianmartorell
Copy link
Contributor

ianmartorell commented Mar 2, 2018

That's not the latest version of subscriptions-transport-ws though! I'm not sure what version introduced the fix, but these are the ones I'm on right now, everything working perfectly:

    "apollo-cache-inmemory": "^1.1.5",
    "apollo-client": "^2.2.0",
    "apollo-link": "^1.0.7",
    "apollo-link-http": "^1.3.2",
    "apollo-link-ws": "^1.0.4",
    "apollo-utilities": "^1.0.4",
    "graphql": "^0.12.3",
    "subscriptions-transport-ws": "^0.9.5"

Also, you don't need graphql-subscriptions on the client.

Make sure to use the same version of graphql on the server as well.

@jcteague
Copy link

jcteague commented Mar 2, 2018 via email

@Kikketer
Copy link

Kikketer commented Aug 8, 2018

This issue is nearly a year old, and I'm getting the following error:

index.js:2177 Unhandled GraphQL subscription error TypeError: Cannot read property 'subscription' of undefined
    at SubscriptionHandshakeLink../node_modules/aws-appsync/lib/link/subscription-handshake-link.js.SubscriptionHandshakeLink.request

Should I still be using version 0.10? Right now I'm using version 11.7 and am somewhat tied to that version since the aws-appsync@1.2.1 dependency is using that version.

@ianmartorell
Copy link
Contributor

You might have an old version of subscriptions-transport-ws. This issue was caused by graphql expecting a Promise from version ^0.11.0 onwards, and subscriptions-transport-ws not returning one. It was fixed and merged last September in #261, so I would recommend upgrading both of the packages to the latest versions you can, and you should be good. Going back to 0.10 is probably not a good idea, as there's bound to have been countless other bug fixes and improvements since then.

@Kikketer
Copy link

Kikketer commented Aug 9, 2018

Thanks @ianmartorell . I discovered the issue I had, I wasn't matching the arguments in my query to what I had defined in my schema server side. All my libraries are up to speed now and working, the only one I had to downgrade was graphql from 0.13.2 to 0.13.0.

  "dependencies": {
    "apollo-cache-inmemory": "^1.2.6",
    "apollo-client": "^2.3.7",
    "apollo-link-http": "^1.5.4",
    "aws-appsync": "^1.3.3",
    "aws-appsync-react": "^1.1.3",
    "graphql": "0.13.0",  << Might be able to be updated to 0.13.2
    "graphql-tag": "^2.9.2",
    "react": "^16.1.1",
    "react-apollo": "^2.1.9",
    "react-dom": "^16.1.1"
  }

Be sure to match your gql query with what's defined in the schema (in my js client):

export default gql(`
subscription {
  createdEvent {
    name,
    when,
    where,
    description
  }
}`)

And my schema (defined on the server side in aws appsync):

type Subscription {
	createdEvent: Event
		@aws_subscribe(mutations: ["createEvent"])
}

Could probably close this issue.

@glasser glasser closed this as completed Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants