在AppSync @auth规则中,如何将ownerField设置为数组中的属性?

时间:2019-12-17 20:48:10

标签: graphql aws-appsync

想象一下,我有一个以下User类型的AppSync GraphQL模式,一个Post类型的editors类型的User字段设置为type User @model @auth(rules: [ { allow: owner } ]) { id: ID! owner: String! username: String! } type Post @model @auth(rules: [ { allow: owner }, # Can I do this? # { allow: owner, ownerField: "editors.owner", operations: [update] } ]) { id: ID! owner: String! title: String! content: String editors: [User] } s数组:

@auth

如何创建User规则以授予对editors数组中的public static Git openOrInit(Path repoPath) throws IOException, GitAPIException { Git git; try { git = Git.open(repoPath.toFile()); } catch (RepositoryNotFoundException e) { log.warn("Git repository may not exist, we will try to initialize an empty repository", e); git = Git.init().setDirectory(repoPath.toFile()).call(); } return git; } 的更新权限?

1 个答案:

答案 0 :(得分:2)

如果您正在使用Amazon Cognito用户池,则应将Post内部的编辑器类型设置为String数组,并将值设置为要访问的用户的Cognito ID。 in the amplify cli documentation对此进行了说明。

要使编辑器的类型为User,我建议您创建另一个名称不同的参数(例如editorUsers),然后按照here

将其连接到User模型。

您的架构应如下所示:

type User
@model
@key(name: "byUser", fields: ["username"]) 
@auth(rules: [
 { allow: owner }
])
{
  id: ID!
  owner: String!
  username: String!
}

type Post
@model
@auth(rules: [
  { allow: owner },
  { allow: owner, ownerField: "editors", operations: [update] }
])
{
  id: ID!
  owner: String!
  title: String!
  content: String
  editors: [String]
  editorsUsers: [User] @connection(keyName: "byUser", fields: ["id"])
}