@isUnique 在 GraphQL SDL(aws appsync)中不起作用

@isUnique not working in GraphQL SDL( aws appsync)

我是 graphql.Iam 使用 aws 实现 react-native 应用程序的新手 appsync.We 在实现 @isUnique 时遇到问题并给我一个错误

Failed to parse schema document - ensure it's a valid SDL-formatted document.
type Person {
id: ID! @isUnique
createdAt: String!
updateAt: String!
name: String!
messages: [Messages!]!
    @relation(name: "UserMessages")}

我想为 schema.How 中的每个用户生成一个随机 ID 我们可以实现吗? 提前致谢!!

首先,如果您使用的是 appolo-server,则为 @unique;如果您使用 graphcool,则为 @isUnique。其次,ids 默认是唯一的,不需要@unique。它用于其他字段,例如电子邮件或用户名。

看这里Schema directives - Appolo 如果您使用的是 Graphcool this

@isUnique 是特定于提供者的指令。如果您想在服务器上使用 AWS AppSync 生成唯一标识符,您可以在解析器中使用 $util.autoId()AWS AppSync - Up and Running 博客 post 有详细信息。