[英]Relay subscription error: Expected null to be a GraphQL composite type
I want to create a subscription, but when I am compiling to relay I am getting this error: ERROR: Expected null to be a GraphQL composite type.
我想创建一个订阅,但是在编译进行中继时出现此错误:
ERROR: Expected null to be a GraphQL composite type.
I think what my graphql definition is wrong, but I have no clue about how to check it. 我认为我的graphql定义是错误的,但是我不知道如何检查它。 Sadly the documentation at relay site is too simple.
遗憾的是,中继站点上的文档太简单了。 Do you know what are the rules in order to create a proper graphql for a subscription?
您知道为订阅创建适当的graphql的规则是什么?
In theory the file schema.graphql is autogenerated, but I can't find how to add a subscription in it from tools. 从理论上讲,文件schema.graphql是自动生成的,但是我找不到如何从工具中添加预订的方式。
I followed this tutorial and manually added a type for the subscriptions adapting this schema file to my case. 我按照本教程进行操作,并手动为订阅添加了一种类型,以使此模式文件适合我的情况。 This is my final schema file:
这是我的最终模式文件:
type Subscription {
Story(filter: StorySubscriptionFilter): StorySubscriptionPayload
}
input StorySubscriptionFilter {
mutation_in: [_ModelMutationType!]
}
type StorySubscriptionPayload {
mutation: _ModelMutationType!
node: Story
updatedFields: [String!]
previousValues: StoryPreviousValues
}
enum _ModelMutationType {
CREATED
UPDATED
DELETED
}
type StoryPreviousValues {
createdAt: DateTime!
id: ID!
updatedAt: DateTime!
}
Expected null to be a GraphQL composite type.
预期null为GraphQL复合类型。
Above error simply means that you are missing a type in the schema you are using for compiling that you are using in your code. 上面的错误仅表示您在代码中缺少用于编译的架构中的类型。
One of the easiest way to get the latest updated schema matching with the GraphQL server is to use get-graphql-schema
获取与GraphQL服务器匹配的最新更新架构的最简单方法之一是使用
get-graphql-schema
get-graphql-schema graphql server url > schema.graphql
replace graphql server url with the actual url 用实际网址替换graphql服务器网址
and then use the updated schema.graphql
for compiling 然后使用更新的
schema.graphql
进行编译
yarn relay-compiler --src ./src --schema schema.graphql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.