apollo-link-webextensions-messaging
Apollo link that, in a WebExtension, forwards GraphQL operations between processes
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
import { createWebExtensionMessagingExecutorListener } from 'apollo-link-webextensions-messaging';
import { SchemaLink } from 'apollo-link-schema';
import schema from './path/to/your/schema';
const link = new SchemaLink({
schema,
context: operation => ({
sender: operation.getContext().port.sender,
})
});
const listener = createWebExtensionMessagingExecutorListener({
link,
});
chrome.runtime.onConnect.addListener(listener);
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({
link: createWebExtensionsMessagingLink(port),
cache: new InMemoryCache(),
queryDeduplication: false,
});
client.query(MY_QUERY);
License
MIT