【问题标题】:Does relay require an id field in the the database?中继是否需要数据库中的 id 字段?
【发布时间】:2018-02-04 15:13:53
【问题描述】:

嗯,我使用 Relay 已经有一段时间了,但我意识到我仍然不确定使用 Relay、Graphql、React 和 Dynamodb 的一些基本方面。

我使用 Dynamodb 作为数据库,而 Dynamodb 不鼓励使用 uuid 作为标识符。同时,relay 的 Nodedefinitions 函数期望输出一个带有 type 和 id 字段的对象,所以我的问题是,你能协调 Relay 和 Dynamodb 的最佳实践吗?

还是只有我不明白?

【问题讨论】:

    标签: amazon-dynamodb relayjs relay


    【解决方案1】:

    Relay 对您的数据库没有任何要求。您可以在 Dynamo 中使用任何您想要的主键。

    你最终会得到两个函数:

    1. f(relayId) -> dynamoEntity
    2. g(dynamoEntity) -> relayId

    这些功能可以随心所欲地实现。例如。也许您可以对 Dynamo 主键进行 base64 编码以生成中继 ID。

    【讨论】:

    • 如果我要导出一个中继节点对象,例如:export const { nodeInterface, nodeField } = nodeDefinitions(idResol ver, typeResolver); 并且 idResolver 函数具有中继 fromGlobalId 像这样 ` const { type, id } = fromGlobalId(globalId);, should I change the id to a function that takes in a relayId like const {类型,f(relayId)} = fromGlobalId(globalId);`
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 2022-09-22
    • 2016-08-19
    • 2011-02-03
    相关资源
    最近更新 更多