Socket
Socket
Sign inDemoInstall

apollo-link-webextensions-messaging

Package Overview
Dependencies
10
Maintainers
7
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apollo-link-webextensions-messaging

> Apollo link that, in a WebExtension, forwards GraphQL operations between processes


Version published
Weekly downloads
8
increased by700%
Maintainers
7
Install size
884 kB
Created
Weekly downloads
 

Readme

Source

Apollo link that, in a WebExtension, forwards GraphQL operations between processes

NPM Version

Install

npm i -S apollo-link-webextensions-messaging

Features

  • Supports response streaming. Perfect to use with reactive-graphql and apollo-link-reactive-schema
  • Compatible with Chrome Extensions and Web Extensions APIs
  • Independent of Port creation method: adaptable for cross-extension messaging or native messaging
  • Messaging context passing: use messaging Port (and esp. MessageSender) in local GraphQL resolvers

Usage

// ------------------
// in background page
import { createWebExtensionMessagingExecutorListener } from 'apollo-link-webextensions-messaging';
import { SchemaLink } from 'apollo-link-schema';
import schema from './path/to/your/schema';

// local schema execution
const link = new SchemaLink({
  schema,
  context: operation => ({
    // `createWebExtensionMessagingExecutorListener` will
    // add `port`, the `onConnect`'s `Port` as Operation's context
    // we extract the `MessageSender` into GQL's context so that
    // it can be used in resolvers
    sender: operation.getContext().port.sender,
  })
});

const listener = createWebExtensionMessagingExecutorListener({
  link,
});

chrome.runtime.onConnect.addListener(listener);


// ----------------
// in content script
import { createWebExtensionsMessagingLink } from 'apollo-link-webextensions-messaging';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';

const port = chrome.runtime.connect();

const client = new ApolloClient({
  // can also be `createWebExtensionsMessagingLink((operation) => port)`
  link: createWebExtensionsMessagingLink(port),
  cache: new InMemoryCache(),
  // from experience, if `queryDeduplication` is true,
  // `client.watchQuery` unsubscription will not be
  // properly passed down to the `link`
  queryDeduplication: false,
});

client.query(MY_QUERY);

License

MIT

FAQs

Last updated on 16 Sep 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc