question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When sending a subscription with fragments, the request is sent to the http endpoint instead of the ws endpoint

See original GitHub issue

@ntziolis commented on Sat Aug 18 2018

Summary When using fragments + NOT naming the subscription Prisma (not app endpoint) returns { data: null } straight away + closes the connection (no spinner in playground).

To Reproduce Steps to reproduce the behavior:

  1. Feel free to use my endpoint: https://eu1.prisma.sh/public-silvermole-100/subscription-fragment/dev or Create new service in prisma with the following schema:
type Post {
  id: ID! @unique
}
  1. Execute the below in playground against prisma endpoint
fragment PostFragment on Post{
  id
}
subscription {post{node{  ...PostFragment  }}}
  1. See error Returns { data: null } straight away + closes the connection (no spinner in playground)

Expected behavior Subscription not be closed (spinning wheel in playground). Data should be returned when there is an event the subscription matches.

Screenshots If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

  • Prisma Server: 1.15-beta-1 (current dev servers)

Context When either giving the subscription a name or removing the fragments it works just fine (spinning wheel in playground):

fragment PostFragment on Post{
  id
}
subscription SomeName{post{node{  ...PostFragment  }}}

or

subscription {post{node{  id  }}}

@marktani commented on Fri Sep 28 2018

This seems to be a bug in the Playground. Instead of opening a websocket connection, the Playground seems to send a query, which returns the null data:

curl 'https://eu1.prisma.sh/public-silvermole-100/subscription-fragment/dev' -H 'origin: https://eu1.prisma.sh' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9,de;q=0.8,es;q=0.7' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' -H 'content-type: application/json' -H 'accept: */*' -H 'referer: https://eu1.prisma.sh/public-silvermole-100/subscription-fragment/dev' -H 'authority: eu1.prisma.sh' --data-binary '{"operationName":null,"variables":{},"query":"fragment PostFragment on Post {\n  id\n}\n\nsubscription {\n  post {\n    node {\n      ...PostFragment\n    }\n  }\n}\n"}' --compressed

results in

{
  "data" : {
    "post" : null
  }
}

As you can see, the endpoint is https://eu1.prisma.sh/public-silvermole-100/subscription-fragment/dev and not wss://..., so what the server returns for this is undefined.

I’ll move this to the graphql-playground repository. As a workaround, use any other subscription client.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Miragecodercommented, Apr 12, 2019

I’m currently working on a project with Apollo - which also ships with the GraphQL Playground - and I ran into the same behaviour when using fragments on a subscription. With my situation, I can workaround this issue using inline fragments. Maybe that can help for a while!

0reactions
dunatroncommented, Jan 6, 2020

Upgrading the prisma-binding and naming the subscriptions on the client seems to fix the issue. e.g.

const MESSAGE_CREATED_SUBSCRIPTION = gql`
  subscription($where: MessageSubscriptionWhereInput) {
    messageSub(where: $where) {
      mutation
      node {
        ...Message
      }
    }
  }
  ${fragments.message}
`;

becomes

const MESSAGE_CREATED_SUBSCRIPTION = gql`
  subscription NEW_MESSAGE_SUB($where: MessageSubscriptionWhereInput) {
    messageSub(where: $where) {
      mutation
      node {
        ...Message
      }
    }
  }
  ${fragments.message}
`;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: When Subscription has fragments but is NOT named Prisma ...
When sending a subscription with fragments, the request is sent to the http endpoint instead of the ws endpoint graphql/graphql-playground#846.
Read more >
Subscriptions - Apollo GraphQL Docs
When Apollo Client executes the OnCommentAdded subscription, it establishes a connection to your GraphQL server and listens for response data. Unlike with a ......
Read more >
Make sure your endpoint is ready to process Amazon SNS ...
When you subscribe an HTTP endpoint, Amazon SNS sends it a subscription confirmation request. Your endpoint must be prepared to receive and process...
Read more >
Web Services Eventing (WS-Eventing) - W3C
To create, renew, and delete subscriptions, subscribers send request messages to event sources and subscription managers.
Read more >
Configuring endpoint URL information for HTTP bindings - IBM
You can use either the administrative console or property files to configure and manage HTTP endpoint URL fragments. To learn about using property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found