预期 undefined 是 GraphQL 叶类型

Posted

技术标签:

【中文标题】预期 undefined 是 GraphQL 叶类型【英文标题】:Expected undefined to be a GraphQL leaf type 【发布时间】:2018-10-02 14:08:09 【问题描述】:

在我的项目中运行中继编译器时出现以下错误

$ get-graphql-schema http://localhost/api/office > schema.graphql   
$ relay-compiler --src ./src/client --schema schema.graphql  
Watchman:  Watchman was not found in PATH.  See https://facebook.github.io/watchman/docs/install.html for installation instructions  
HINT: pass --watch to keep watching for changes.  

Writing js  
ERROR:  
Expected undefined to be a GraphQL leaf type.  
error Command failed with exit code 100.

关于如何进行调试的任何建议,我项目中最近的唯一变化(著名的遗言)是升级到中继 1.5。我怀疑它是 graphql 模式中的一些东西,需要更改以适应新的中继编译器,但我没有看到它。

schema.graphql 如下:

schema 
  query: RootQuery
  mutation: RootMutation


type Delete 
  n: String
  nModified: String
  ok: String


type Room 
  _uuid: String
  roomName: String
  serviceName: String
  roomURL: String
  roomID: String
  phoneNumber1: String
  phoneNumber2: String
  participantCode: String
  moderatorCode: String
  video: String
  otherLink1: String
  otherLink2: String
  color: String


# Mutation interface
type RootMutation 
  createRoom(
    # Name of the room owner
    ownerName: String

    # Email of the room owner
    ownerEmail: String!

    # Name of the room
    roomName: String!

    # Service name
    serviceName: String!

    # URL
    roomURL: String!

    # ID to meeting room
    roomID: String

    # Phone number 1
    phoneNumber1: String!

    # Phone number 2
    phoneNumber2: String

    # Participant code
    participantCode: String!

    # Moderator code
    moderatorCode: String!

    # Video
    video: String

    # Color
    color: String
  ): Room
  deleteRoom(
    # Email of the room owner
    ownerEmail: String!

    # Name of the room
    roomName: String!
  ): Delete


type RootQuery 
  meetingsUser(ownerEmail: String!, _uuid: String, refetch: Boolean): [User]


type User 
  _id: String
  ownerEmail: String
  ownerName: String

  # Provides a list of all rooms owned by the user
  rooms: Room

【问题讨论】:

【参考方案1】:

这是因为您的类型缺少全局 id 字段。

我有同样的问题,但添加

type MyType = 
  id: ID
   ...

解决了问题。

另见https://github.com/facebook/relay/issues/1880#issuecomment-307705428

【讨论】:

太棒了。谢谢。

以上是关于预期 undefined 是 GraphQL 叶类型的主要内容,如果未能解决你的问题,请参考以下文章

Graphql 查询结果返回 undefined

预期的 Schema ... 是一个 GraphQL 模式

GraphQL 教程 - 预期未定义为 GraphQL 模式

使用 graphql-tools、apollo-link-schema 和 react-hooks 在模拟时总是返回 undefined

GraphQl 生成语法错误:预期 $,找到 ]

出现错误:未处理的拒绝(错误):无凭据 | if (typeof opt.graphql_headers !== 'undefined' && | 在 GraphQLAPI.ts 文件