我正在尝试使用 ActionCable 和graphql-ruby
gem 来实现 GraphQL 订阅。
我从这个链接中发现,需要创建客户端需要订阅的 GraphQL 通道。通常,在ActionCable中,我们会在动作stream_from
中需要通道subscribed
。但是,链接中的示例指定了execute
带参数的方法。这个方法什么时候会被执行呢?
此外,该文档还说明了See Apollo Client or Relay Modern
客户端的使用情况。是否必须使用其中任何一种,或者我可以使用 CoffeeScript 来订阅和更新 UI 吗?
ruby ruby-on-rails graphql graphql-subscriptions graphql-ruby
我正在尝试使用API制作Apollo GraphQL
并react
在使用subscriptions-transport-ws
库的GraphQL订阅的帮助下更新组件实时.对于删除操作,我收到TypeError: Cannot add/remove sealed array elements
错误.这是来自试图从订阅更新数据的react组件的代码.
componentWillReceiveProps(nextProps) {
if (!this.subscription && !nextProps.data.loading) {
let { subscribeToMore } = this.props.data
this.subscription = [subscribeToMore(
{
document: postDeleted,
updateQuery: (previousResult, { subscriptionData }) => {
const delPost = subscriptionData.data.postDeleted;
const mainData = previousResult.Posts;
let post = mainData.find(post => post.id == delPost.id);
let updatedList = mainData.splice(post, 1);
return updatedList;
},
}
)]
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下 GraphQL 订阅,运行良好:
subscription voucherSent($estId: Int!) {
voucherSent(estId: $estId) {
id
name
usedAt
sentAt
}
}
Run Code Online (Sandbox Code Playgroud)
但以下发送“无法读取未定义的属性‘用户’”错误
subscription voucherSent($estId: Int!) {
voucherSent(estId: $estId) {
id
name
usedAt
sentAt
owner {
id
username
}
}
}
Run Code Online (Sandbox Code Playgroud)
Apollo GraphQL 订阅是否处理嵌套查询?
这是我的解析器代码:
return models.Voucher.update({
sentAt: moment().format(),
usedIn: args.sentTo,
}, { where: { id: args.id } })
.then(resp => (
models.Voucher.findOne({ where: { id: args.id } })
.then((voucher) => {
pubsub.publish(VOUCHER_SENT, { voucherSent: voucher, estId: voucher.usedIn });
return resp;
})
))
Run Code Online (Sandbox Code Playgroud) 使用 graphql-yoga 我试图编写笑话测试来覆盖订阅。
如果订阅有效(使用身份验证),我能够成功测试快乐路径。不幸的是,我无法测试订阅 websocket 连接被拒绝的情况。
在我的服务器设置中,我拒绝任何未通过我的身份验证标准的 websocket 连接:
const app = await server.start({
cors,
port: process.env.NODE_ENV === "test" ? 0 : 4000,
subscriptions: {
path: "/",
onConnect: async (connectionParams: any) => {
const token = connectionParams.token;
if (!token) {
throw new AssertionError({ message: "NO TOKEN PRESENT" });
}
const decoded = parseToken(token, process.env.JWT_SECRET as string);
const user = await validateTokenVersion(decoded, redis);
if (user === {}) {
throw new AssertionError({ message: "NO VALID USER" });
}
return { user }; …
Run Code Online (Sandbox Code Playgroud) typescript jestjs graphql apollo-server graphql-subscriptions
我目前正在使用 AWS Amplify 框架构建 React Native 应用程序。
在我的应用程序中,应该有一个实时仪表板,当新项目添加到数据库时,该仪表板会得到更新。
为了实现此功能,我使用 Amplify 和 AppSync API 进行 GraphQL 订阅。
由于某种原因,订阅不会响应数据库上发生的事件。
这是我的代码:
import React, { useEffect } from 'react';
import { API, graphqlOperation } from 'aws-amplify';
import * as subscriptions from '../../src/graphql/subscriptions';
const App = () => {
useEffect(() => {
subscribeUsers();
}, []);
const subscribeUsers = async () => {
await API.graphql(graphqlOperation(subscriptions.onCreateUser, {appId: appId})).subscribe({
next: (todoData) => console.log(todoData),
error: (err) => console.log(err)
});
}
...
}
export default App;
Run Code Online (Sandbox Code Playgroud)
这是我的 index.js 代码:
import …
Run Code Online (Sandbox Code Playgroud) 我是 graphQL 石墨烯(python)的新手。我想知道是否可以使用石墨烯创建订阅根类型。谢谢
graphql graphene-python graphql-subscriptions graphql-mutation
graphql ×6
apollo ×1
aws-amplify ×1
graphql-ruby ×1
javascript ×1
jestjs ×1
react-apollo ×1
react-native ×1
reactjs ×1
ruby ×1
typescript ×1