admin管理员组文章数量:1122923
I'm using AWS Amplify with the CLI (version 12.13.1) and the Amplify backend library to generate code for my project. Everything was working well until I added a new Owner: User
field in the Event
model. After this change, when I try to fetch invites with the listInviteByUserId
query, I get the following error:
"graphQLErrors": [
{
"path": [
"listInviteByUserId",
"items",
7,
"event",
"Owner"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 9,
"column": 9,
"sourceName": null
}
],
"message": "Value for field '$[operation]' not found."
}
]
Here is the relevant part of my GraphQL schema:
type User
@model
@auth(
rules: [
{ allow: private, provider: iam }
{ allow: owner }
]
) {
id: ID
owner: ID
username: String
name: String
}
type Event
@model
@auth(
rules: [
{ allow: private, provider: iam }
{ allow: owner }
]
) {
id: ID
owner: ID
Owner: User @hasOne(fields: ["owner"])
userId: ID
@index(
name: "listEventByUserId"
queryField: "listEventByUserId"
sortKeyFields: ["createdAt"]
)
name: String
description: String
partners: [Event] @hasMany(fields: ["partnerIds"])
partnerIds: [ID]
}
type Invite
@model
@auth(
rules: [
{ allow: private, provider: iam }
{ allow: owner, operations: [read] }
]
) {
id: ID
owner: ID
event: Event @hasOne(fields: ["eventId"])
user: User @hasOne(fields: ["userId"])
eventId: ID @index(name: "listInviteByEventId", queryField: "listInviteByEventId", sortKeyFields: ["createdAt"])
userId: ID @index(name: "listInviteByUserId", queryField: "listInviteByUserId", sortKeyFields: ["createdAt"])
isAccepted: Boolean
}
What I’ve tried:
Custom Resolver for Owner Field:
- I created a custom resolver (
amplify/backend/api/GraphApi/resolvers/Event.Owner.req.vtl
) to resolve theOwner
field. Here's the code I added:
## $util.toJson({"version":"2018-05-29","payload":{}})
#if( $ctx.stash.deniedField )
#return($util.toJson(null))
#end
#set( $partitionKeyValue = $ctx.source.owner )
#if( $util.isNull($partitionKeyValue) )
#return
#else
#set( $idValue = $util.defaultIfNullOrBlank($partitionKeyValue, "___xamznone____") )
#set( $GetRequest = {
"version": "2018-05-29",
"operation": "GetItem"
} )
$util.qr($GetRequest.put("key", {
"id": {
"S": "$idValue"
}
}))
#if( !$util.isNullOrEmpty($ctx.stash.authFilter) )
$util.qr($GetRequest.put("filter", $util.parseJson($util.transform.toDynamoDBFilterExpression($ctx.stash.authFilter))))
#end
$util.toJson($GetRequest)
#end
- Modified Auth Rules: I also tried modifying the auth rules in the User model, but this didn’t resolve the issue.
However, when I query for partners
in the Event
model (which also uses a @hasMany
relationship), it works correctly. The issue seems to be isolated to the Owner
field in the Event
model.
What am I missing? Why does fetching the Owner
field from the Event
model cause this error, while fetching related fields like partners
works fine? Any insights on how to fix the issue with the custom resolver or GraphQL setup would be greatly appreciated!
Edit
I added a new model and associated the User
model on field owner
and it worked successfully. But when it generated gql for Event
model it's not working as expected.
本文标签: aws appsyncAWS Amplify CLIGenerating wrong resolversStack Overflow
版权声明:本文标题:aws appsync - AWS Amplify CLI - Generating wrong resolvers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736531221a1944350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论