@absinthe/ socket-apollo-link (英语)
阿波罗连线
安装
使用 无
$ npm install --save @absinthe/socket-apollo-link
使用 线条
$ yarn add @absinthe/socket-apollo-link
实例
- 创建 Absinthe SocketLink (
absinthe-socket-link.js(中文(简体) )
// @flow
import * as AbsintheSocket from "@absinthe/socket";
import {createAbsintheSocketLink} from "@absinthe/socket-apollo-link";
import {Socket as PhoenixSocket} from "phoenix";
export default createAbsintheSocketLink(AbsintheSocket.create(
new PhoenixSocket("ws://localhost:4000/socket")
));
- 使用 Absinthe SocketLink 发送全部操作
// @flow
import ApolloClient from "apollo-client";
import {InMemoryCache} from "apollo-cache-inmemory";
// see example 1
import absintheSocketLink from "./absinthe-socket-link";
const client = new ApolloClient({
link: absintheSocketLink,
cache: new InMemoryCache()
});
- 使用 Absinthe SocketLink 订阅并使用 HttpLink 发送查询和突变
// @flow
import ApolloClient from "apollo-client";
import {createHttpLink} from "apollo-link-http";
import {hasSubscription} from "@jumpn/utils-graphql";
import {InMemoryCache} from "apollo-cache-inmemory";
import {split} from "apollo-link";
// see example 1
import absintheSocketLink from "./absinthe-socket-link";
const link = split(
operation => hasSubscription(operation.query),
absintheSocketLink,
createHttpLink({uri: "/graphql"})
);
const client = new ApolloClient({
link,
cache: new InMemoryCache()
});
API 密码
创建 Absinthe SocketLink 链接
创建终止的 AploLink 以请求使用给定的操作 Absinthe Socket 实例
参数
absintheSocket饮用沙袋onErrorElementType < 观察员 < 结果,变量 > ,"onError"> 翻译:onStartElementType < 观察员 < 结果,变量 > ,"onStart"> 翻译:
参考资料
许可证
麻省理工学院 :版权:Jumpn Limited.