【问题标题】:Appsync Fine Graine Control on Mutation with Multiple TablesAppsync 对多表突变的细粒度控制
【发布时间】:2018-11-02 06:49:56
【问题描述】:

我有以下模式,事件的作者可以在其中记录事件。只有事件的作者才能创建注释。我将author 存储在事件中。但是,我发现其他用户可以通过简单地传递另一个用户事件的 eventId 来为他们未创作的事件创建注释,如下所示:

mutation {
  noteOnEvent(input: { eventId: "***", content: "A comment"}) {
    eventId
    content
  }
}

如何防止这种情况发生?我看不到在 noteOnEvent 解析器中访问 EventTable 作者的方法

架构

type Note {
    eventId: ID!
    notetId: ID!
    content: String
    author: String

}

input CreateNoteInput {
    eventId: ID!
    noteId: String!
    content: String
}

type Event {
    id: ID!
    name: String
    author: String 
    notes: [Note]
}

【问题讨论】:

    标签: aws-appsync


    【解决方案1】:

    您可以使用嵌套解析器完成此操作。

    如果你稍微修改你的架构,你可以像这样完成它:

    type EventCheckedNote {
      // Add a resolver on note which creates the note. The event will be available as $cxt.source, and you can make an authZ check before making the mutation.
      note: Note
    }
    
    type Mutation {
      // Add a resolver on noteOnEvent which queries the Event table.
      noteOnEvent(input: CreateNoteInput!): EventCheckedNote
    }
    

    这里是使用嵌套解析器执行涉及多个数据源的授权检查的教程:https://hackernoon.com/graphql-authorization-with-multiple-data-sources-using-aws-appsync-dfae2e350bf2

    【讨论】:

    • 谢谢@michalwillingham,解析器会是什么样子?这是令人困惑的部分
    • oh @Michael-Willingham 如何访问原始输入参数以在 note.Note 解析器中创建注释? .他们总是空虚地过去
    • 如果原始输入参数在子解析器中无法通过 $ctx.arguments 获得,您可以尝试在父解析器的响应映射模板中返回输入参数的映射。然后,note.Note 解析器可以通过 $ctx.source.{YourInputArgument} 访问父解析器返回的数据。这是解析器上下文的文档:docs.aws.amazon.com/appsync/latest/devguide/…
    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2022-01-03
    • 2014-11-29
    • 2018-11-05
    相关资源
    最近更新 更多