Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link-optimistic

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-optimistic

An Apollo link that immediately returns an optimistic response before returning the server response

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Build Status codecov

An Apollo Link that immediately returns an optimistic response provided in the context of the request, before returning the server response(s).

Install

npm install apollo-link-optimistic

or

yarn add apollo-link-optimsitic

Usage

import { ApolloLink } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { RetryLink } from 'apollo-link-retry';
import gql from 'graphql-tag';

import OptimisticLink from 'apollo-link-optimistic';

this.link = ApolloLink.from([
    new OptimisticLink(),
    new HttpLink({ uri: URI_TO_YOUR_GRAPHQL_SERVER }),
]);

const optimisticResponse = {
    data: {
        hello: 'Optimistic World',
    },
};

const op = {
    query: gql`{ hello }`,
    context: {
        // OptimisticLink gets the optimistic response from the context.
        optimisticResponse,
    },
};

link.execute(op).subscribe({
    next(response) { console.log(response.data.hello); },
    complete() { console.log('complete!'); },
});

// Assuming the server responds with { data: { hello: "Server World" } }
// This code will output:
// "Optimistic World"
// "Server World"
// "complete!"

Keywords

FAQs

Package last updated on 10 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc