React 与 Apollo GraphQL 订阅 return 值
React with Apollo GraphQL subscriptions return value
我正在使用 Apollo GraphQL,并且正在努力降低 pubsub 的发布方面。这是我拥有的:
发布:
const tst = { string1: 'hi', string2: 'hello' };
pubsub.publish("sub", tst);
GraphQL 订阅
subscription ($Id: Int!) {
test(Id: $Id){
string1
string2
}
}
当我在 graphiql 中尝试这个时,它只是 returns [Object] [Object] 向我发出出错的信号。虽然我找不到错误代码。如果我将两者更改为:
发布:
pubsub.publish("sub", tst: 'hi');
GraphQL 订阅
subscription ($Id: Int!) {
test(Id: $Id)
}
当发布被触发时,GraphiQL 将 return 'hi'。为什么我不能return第一个设置?
编辑
架构如下:
type Test {
string1: String
string2: String
}
这是订阅架构
test(Id: Int!): Test
找到我的答案。我发布有误。
它应该在选项参数中使用 test 而不是 tst:
pubsub.publish("sub", { test: tst });
我正在使用 Apollo GraphQL,并且正在努力降低 pubsub 的发布方面。这是我拥有的:
发布:
const tst = { string1: 'hi', string2: 'hello' };
pubsub.publish("sub", tst);
GraphQL 订阅
subscription ($Id: Int!) {
test(Id: $Id){
string1
string2
}
}
当我在 graphiql 中尝试这个时,它只是 returns [Object] [Object] 向我发出出错的信号。虽然我找不到错误代码。如果我将两者更改为:
发布:
pubsub.publish("sub", tst: 'hi');
GraphQL 订阅
subscription ($Id: Int!) {
test(Id: $Id)
}
当发布被触发时,GraphiQL 将 return 'hi'。为什么我不能return第一个设置?
编辑
架构如下:
type Test {
string1: String
string2: String
}
这是订阅架构
test(Id: Int!): Test
找到我的答案。我发布有误。
它应该在选项参数中使用 test 而不是 tst:
pubsub.publish("sub", { test: tst });