当前位置 : 主页 > 网页制作 > React >

在GraphQL中,您如何进行基本扩展类型?

来源:互联网 收集:自由互联 发布时间:2021-06-15
例如,宠物是拥有所有者和名字的动物. type Animal { species: String}type Pet extends Animal { owner: Owner name: String} 目前这在GraphQL中是不可能的,但是有一个实验包可能对此有用. https://github.com/Sydsv
例如,宠物是拥有所有者和名字的动物.

type Animal {
  species: String
}

type Pet extends Animal {
  owner: Owner
  name: String
}
目前这在GraphQL中是不可能的,但是有一个实验包可能对此有用.

https://github.com/Sydsvenskan/node-graphql-partials

见例子:

partial LinkFields {
  links(
    rel: String
    type: String
  ): [Link]
}

partial DocumentFields using LinkFields {
  uuid: ID!

  # The document type, such as x-im/article
  type: String
  # If specified, then a list of the products to which this document's availability is limited
  products: [String]
  # The human readable name of the document, often used publicly to identify the document
  title: String

  # The specific path on the web page where this document is publicly available
  path: String

  # A single metadata block
  metaBlock(
    # The specific metadata block type to get
    type: String
  ): MetadataBlock
}

interface Document using DocumentFields {}

type AuthorDocument implements Document using DocumentFields {}

结果如下:

type AuthorDocument implements Document {
  links(
    rel: String
    type: String
  ): [Link]

  uuid: ID!

  # The document type, such as x-im/article
  type: String
  # If specified, then a list of the products to which this document's availability is limited
  products: [String]
  # The human readable name of the document, often used publicly to identify the document
  title: String

  # The specific path on the web page where this document is publicly available
  path: String

  # A single metadata block
  metaBlock(
    # The specific metadata block type to get
    type: String
  ): MetadataBlock
}

您还可以做什么,因为这些只是字符串是创建一些帮助函数,修改字符串并插入必要的字段.

如果您在跟进Github上的讨论时遇到了异议,可以查看以下问题.

https://github.com/graphql/graphql-js/issues/703

网友评论