【问题标题】:Should I extend my type with extra fields or create a new type?我应该用额外的字段扩展我的类型还是创建一个新类型?
【发布时间】:2018-11-02 04:20:00
【问题描述】:

我有用于在待办事项列表中创建待办事项的待办事项模板。 我应该为这两个模板创建一种类型并创建这样的待办事项:

type TODO {
    id: ID
    text: String
    type: String
    templateId: ID
    completed: Boolean
}
type TODOList {
    id: ID
    todos: [TODO]
    owner: String
}

或者我应该为模板和创建的待办事项创建单独的类型?

type TODO {
    id: ID
    text: String
    type: String
    templateId: ID
    completed: Boolean
}
type TODOTemplate {
    id: ID
    templateType: String
    templateText: String
}
type TODOList {
    id: ID
    todos: [TODO]
    owner: String
}

或者也许有更方便的方法,我做错了?

【问题讨论】:

    标签: amazon-web-services graphql aws-appsync


    【解决方案1】:

    第二个看起来更好,因为您引入了额外的字段并且可能想要访问它们。在这种情况下,您需要修改您的 TODO 类型:

    type TODO {
        id: ID
        text: String
        type: String
        template: TODOTemplate
        completed: Boolean
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 2018-08-30
      • 1970-01-01
      • 2013-03-21
      相关资源
      最近更新 更多