How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import { ApolloLink, Observable } from 'apollo-link';
     
    export class CustomApolloLink extends ApolloLink {
      request(operation /*, forward*/) {
        //Whether no one is listening anymore
    //Whether no one is listening anymore
        let unsubscribed = false;
     
        return new Observable(observer => {
          somehowGetOperationToServer(operation, (error, result) => {
            if (unsubscribed) return;
            if (error) {
              //Network error
    //Network error
              observer.error(error);
            } else {
              observer.next(result);
              observer.complete(); //If subscriptions not supported
    //If subscriptions not supported
            }
          });
     
          function unsubscribe() {
            unsubscribed = true;
          }
     
          return unsubscribe;
        });
      }
    }
    Docs
  • import { ApolloLink } from '@apollo/client';
    
    const reportErrors = (errorCallback) => new ApolloLink((operation, forward) => {
      const observable = forward(operation);
      // errors will be sent to the errorCallback
      observable.subscribe({ error: errorCallback })
      return observable;
    });
    
    const link = reportErrors(console.error);
    Docs
  • import { Observable } from 'relay-runtime';
    // or
    import { Observable } from '@apollo/client/core';
    // or
    import { Observable } from 'rxjs';
    // or
    import Observable from 'zen-observable';
    // or any other lib which implements Observables as per the ECMAScript proposal: https://github.com/tc39/proposal-observable
    
    const client = createClient({
      url: 'ws://graphql.loves:4000/observables',
    });
    
    function toObservable(operation) {
      return new Observable((observer) =>
        client.subscribe(operation, {
          next: (data) => observer.next(data),
          error: (err) => observer.error(err),
          complete: () => observer.complete(),
        }),
      );
    }
    
    const observable = toObservable({ query: `subscription { ping }` });
    
    const subscription = observable.subscribe({
      next: (data) => {
        expect(data).toBe({ data: { ping: 'pong' } });
      },
    });
    
    // ⏱
    
    subscription.unsubscribe();
    Docs
  • import { ApolloClient, InMemoryCache } from '@apollo/client';
    import { SchemaLink } from '@apollo/client/link/schema';
    import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
    
    const typeDefs = `
      Query {
      ...
      }
    `;
    
    const mocks = {
      Query: () => ...,
      Mutation: () => ...
    };
    
    const schema = makeExecutableSchema({ typeDefs });
    const schemaWithMocks = addMockFunctionsToSchema({
      schema,
      mocks
    });
    
    const apolloCache = new InMemoryCache(window.__APOLLO_STATE__);
    
    const graphqlClient = new ApolloClient({
      cache: apolloCache,
      link: new SchemaLink({ schema: schemaWithMocks })
    });
    Docs
  • //...
    // import ApolloClientIDB from '@wora/apollo-offline/lib/ApolloClientIDB';
    
    const httpLink = new HttpLink({
      uri: "http://localhost:4000/graphql"
    });
    
    const cacheOptions = {
      dataIdFromObject: o => o.id
    };
    
    const client = new ApolloClient({
      link: httpLink,
      cache: new ApolloCache(cacheOptions)
    });
    
    
    
    //...
    
    /morrys/offline-examples mit
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples