想象一下,我有一个以下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;
}
的更新权限?
答案 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"])
}