简体   繁体   English

中继订阅错误:预期为null的是GraphQL复合类型

[英]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.

相关问题 graphql 订阅返回 null 数据 - graphql subscription return null data 收到错误:类型为“查询” [GraphQL,Relay,React]的字段“用户”上的未知参数“ id” - Getting error : Unknown argument “id” on field “user” of type “Query” [GraphQL, Relay, React] GraphQL + Relay现代片段为我提供了一系列空帖 - GraphQL + Relay modern fragment gives me an array of null posts GraphQL / Relay架构无法在“CreateLinkPayload”类型上查询字段“store” - GraphQL/Relay Schema Cannot query field “store” on type “CreateLinkPayload” React.createElement:类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:null - React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: null GraphQL 订阅引发跨域错误 - Cross origin error thrown on GraphQL subscription 连接到Github的GraphQL时Relay和ReactJS给出错误 - Relay and ReactJS give an error when connecting to Github's GraphQL 未处理的 GraphQL 订阅错误 ReferenceError: document is not defined - Unhandled GraphQL subscription error ReferenceError: document is not defined GraphQL和中继过滤UI - GraphQL & Relay Filtering UI 使用Relay和GraphQL进行查询 - Query with Relay and GraphQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM