gpt4 book ai didi

reactjs - Appsync更新和删除突变不起作用

转载 作者:行者123 更新时间:2023-12-03 14:00:22 27 4
gpt4 key购买 nike

我正在为我的APP使用AppSync。这是我的Schema.graphql文件的快速浏览

type Item @model
@auth(rules: [
{ allow: public, provider: apiKey, operations: [read] },
{ allow: groups, groups: ["admin"] }
]) {
id: ID!
name: String!
soldUnits: String!
soldAs: [Float!]
price: Float!
isAvailable: Boolean!
availableAmount: Float!
category: String!
isVeg: Boolean!
offer: [String!]
about: String
storage: String
benifits: String
otherInfo: String
rating: Int
keywords: [String!]
reviews: [String]
images: [String]
updatedBy: String
addedBy: String
qty: Int
inventroy: Inventory @connection(name: "ItemInventory")
}

type User @model {
id: ID!
firstName: String!
lastName: String!
about: String
phoneNumber: String
email: String
countryCode: String
addresses: [Address] @connection
orders: [Order] @connection(name: "OwnOrder")
}

type CartItem {
id: ID!
count: Int!
name: String!
price: Float
}

type Address @model {
id: ID!
lat: Float!
long: Float!
fullAddress: String!
apartment: String!
street: String
area: String!
district: String!
city: String
state: String!
zip: Int!
country: String!
phoneNumber: String!
}

type InventoryAddress @model {
id: ID!
address: Address @connection
inventroy: Inventory! @connection(name: "InventoryAddress")
}

type Order @model {
id: ID!
orderdate: AWSDate!
ordertime: AWSTime!
deliverySlot: String!
deliveryDate: AWSDate!
deliveryInput: String!
deliveryPhoneNumber: String!
deliveryPhoneCountryCode: String!
deliveryAddress: String!
deliveredTime: AWSDate
deliveredDate: AWSDate
deliveryCharges: Float!
totalAmount: Float!
paidAmount: Float!
discount: Float!
unpaidAmount: Float!
status: String!
paymentMethod: String!
paymentId: String!
itemsCount: Int!
items: [CartItem]
deliverAssignedTo: Patron @connection(name: "PatronOrder")
owner: User @connection(name: "OwnOrder")
inventroyDetails: Inventory @connection(name: "InventoryOrder")
}

type Patron @model {
id: ID!
age: Int!
firstName: String!
lastName: String!
about: String
workTime: String
rating: Int!
reviews: [String]
addressProof: String!
role: String
workArea: Address @connection
address: Address @connection
deliveries: [Order] @connection(name: "PatronOrder")
inventroyDetails: Inventory! @connection(name: "PatronInventory")
addedItems: [Item] @connection
}

type Inventory @model {
id: ID!
address: InventoryAddress @connection(name: "InventoryAddress")
patron: [Patron] @connection(name: "PatronInventory")
items: [Item] @connection(name: "ItemInventory")
orders: [Order] @connection(name: "InventoryOrder")
manager: Patron @connection
admins: [Patron] @connection
}

这是我在AppSync中生成的GraphQL模式。
我可以查询数据并创建突变,但是无法更新和删除突变。
mutation UpdateAddressInput {
updateAddress(input:{
id:"af5cd7e6-8213-48b6-aa8e-9d2d6999742c",
area:"New Delhi"
}){
id,
area
}
}

这是一个示例查询,如您在下面看到的返回数据,它没有反射(reflect)在dynamoDB中
{
"data": {
"updateAddress": {
"id": "af5cd7e6-8213-48b6-aa8e-9d2d6999742c",
"area": "Electronic City"
}
}
}

最佳答案

您将在dynamoDB表中看到一个自动生成的字段“_version”。请参阅_version的值以获取要更新的ID区域字段。获取地址时,您将获得一个字段“_version”。
尝试这样的事情

mutation UpdateAddressInput {  
updateAddress(input:{
id:"af5cd7e6-8213-48b6-aa8e-9d2d6999742c",
area:"New Delhi",

_version:variable name // _version value in dynamoDB table for
// the desired row.

}){
id,
area
}
}

关于reactjs - Appsync更新和删除突变不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60877460/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com