【问题标题】:Apollo graphql interface typedefApollo graphql 接口类型定义
【发布时间】:2020-03-01 21:01:35
【问题描述】:

我有阿波罗接口链接这个:

interface PageLayout {
        _id: String!
        id: ID! @globalID
        title: String
        subtitle: String
        template: String! @default(value:"none")
        layout: String
        layoutMobile: String
        showCount: Float
        showCountMobile: Float
        imageHeight: Int
        cardDesign: String
        cardShadow: Int
    }

并拥有实现接口的这种类型:

type PageLayoutBannerRow implements PageLayout {
        _id: String!
        id: ID! @globalID
        title: String
        subtitle: String
        template: String! @default(value:"none")
        layout: String
        layoutMobile: String
        showCount: Float
        showCountMobile: Float
        imageHeight: Int
        cardDesign: String
        cardShadow: Int

        banners: [PageLayoutBanner]! @default(value:[])
    }

对于每种类型,我必须将所有接口属性复制到我的类型。

有什么办法可以像这样写我的类型吗?

type PageLayoutBannerRow implements PageLayout {
        # not copy interface attributes

        banners: [PageLayoutBanner]! @default(value:[])
    }

【问题讨论】:

    标签: graphql apollo apollo-server


    【解决方案1】:

    不幸的是,没有办法解决它。有关详细信息,请参阅文档https://graphql.org/learn/schema/#interfaces

    根据您想要实现的目标,您可能需要查看 unions https://graphql.org/learn/schema/#union-types(但从您的示例看来,您肯定应该使用接口)。

    【讨论】:

      猜你喜欢
      • 2019-07-31
      • 2019-03-10
      • 2021-11-20
      • 2018-01-02
      • 2019-11-07
      • 2019-03-15
      • 2021-04-20
      • 2019-04-03
      相关资源
      最近更新 更多