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.

Hello,

I’m trying to figure it out how to make this work with Relay. According to Relay docs a subscribe function has to return an observable.

When I write this function:

const subscribe = (request, variables) => {
  const subscribeObservable = subscribeClient.subscribe({
    query: request.text,
    operationName: request.name,
    variables,
  })

  // Important: Convert subscriptions-transport-ws observable type to Relay's
  return Observable.from(subscribeObservable);
}

It just doesn’t works, because RelayNetwork returns error: No data returned for operation.

On other hand, when I use subscription-transport-ws it just works.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
sibeliuscommented, Nov 18, 2020

do you wanna migrate this on Relay Workshop (https://github.com/sibelius/relay-workshop/issues/13)

check recipes for the right usage with relay

it is like this

import { createClient } from 'graphql-ws';

const subscriptionsClient = createClient({
  url: config.GRAPHQL_SUBSCRIPTION_URL,
});

export const subscribeFn = (
  operation: RequestParameters,
  variables: Variables,
) => {
  return Observable.create((sink) => {
    if (!operation.text) {
      return sink.error(new Error('Operation text cannot be empty'));
    }
    return subscriptionsClient.subscribe(
      {
        operationName: operation.name,
        query: operation.text,
        variables,
      },
      {
        ...sink,
        error: (err) => {
          if (err instanceof Error) {
            sink.error(err);
          } else if (err instanceof CloseEvent) {
            sink.error(
              new Error(
                `Socket closed with event ${err.code}` + err.reason
                  ? `: ${err.reason}` // reason will be available on clean closes
                  : '',
              ),
            );
          } else {
            // GraphQLError[]
            sink.error(new Error(err.map(({ message }) => message).join(', ')));
          }
        },
      },
    );
  });
};
2reactions
enisdenjocommented, Nov 18, 2020

There is a Client usage with Relay recipe in the readme, check it out! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use a Relay : 4 Steps - Instructables
We need a module to make it possible to control the high voltage/large current with Arduino. That is what a relay can do....
Read more >
What is a Relay and Why Are They So Important? - Amperite
Relays are electric switches that use electromagnetism to convert small electrical stimuli into larger currents. ... These conversions occur when ...
Read more >
Relay - Wikipedia
Relays are used where it is necessary to control a circuit by an independent low-power signal, or where several circuits must be controlled...
Read more >
Understanding Relays & Wiring Diagrams - Swe-Check
A relay is an electrically operated switch. They commonly use an electromagnet (coil) to operate their internal mechanical switching mechanism (contacts).
Read more >
What is a relay, its function, types and relay wiring - ElectGo
Relays are the switches that aim at closing and opening the circuits electronically as well as electromechanically. It controls the opening and ...
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