Aws Amplify:部分更新(突变)
Aws Amplify: Partial updates(mutations)
我有 2 个(希望是新手)问题需要来自社区的意见:
(1) 我更改了应用程序的 schema.graphql 文件。如何确保相应的 queries.js、mutations.js、subscriptions.js 文件已更新?以前这些曾经在我 运行 放大推送命令时得到更新(我认为)但现在他们不再这样做了。
(2) 我如何使用 aws amplify 进行部分突变?例如:如果突变具有 fullName、city,我如何在不从前端应用程序传递 city 的情况下更新 fullName?
我可以在第一个屏幕中编辑全名,在第二个屏幕中编辑城市。如果我没有在第一个屏幕的突变中传递城市,它将被覆盖为空。
这里是突变的样子:
mutations.js:
const updateUserProfile =
mutation UpdateUserProfile(
$input: UpdateUserProfileInput!
$condition: ModelUserProfileConditionInput
) {
updateUserProfile(input: $input, condition: $condition) {
id
fullName
city
createdAt
updatedAt
owner
}
}
;
userprofile.vue
import { Auth } from 'aws-amplify';
import { createUserProfile, updateUserProfile} from '@/graphql/mutations';
const userProfileInput={
id:userId,
fullName:'Ajit Goel',
};
await API.graphql(graphqlOperation(updateUserProfile, {input: userProfileInput}));
schema.graphql:
type UserProfile @model
@key(fields:["id"])
@auth(rules: [{allow: owner}])
{
id: String!
fullName: String
city:String
}
更新突变为运行时控制台出错:
我来帮你吧
放大推送完成后,您应该能够看到变化。请确保在尝试之前保存文件更改。
根据您的架构,城市可能会被设置为带有感叹号的强制性城市。在这种情况下,您可以删除感叹号或将城市设置为空字符串。如果特定操作需要它,您可以稍后在解析器中添加此检查。
我有 2 个(希望是新手)问题需要来自社区的意见:
(1) 我更改了应用程序的 schema.graphql 文件。如何确保相应的 queries.js、mutations.js、subscriptions.js 文件已更新?以前这些曾经在我 运行 放大推送命令时得到更新(我认为)但现在他们不再这样做了。
(2) 我如何使用 aws amplify 进行部分突变?例如:如果突变具有 fullName、city,我如何在不从前端应用程序传递 city 的情况下更新 fullName? 我可以在第一个屏幕中编辑全名,在第二个屏幕中编辑城市。如果我没有在第一个屏幕的突变中传递城市,它将被覆盖为空。
这里是突变的样子:
mutations.js:
const updateUserProfile =
mutation UpdateUserProfile(
$input: UpdateUserProfileInput!
$condition: ModelUserProfileConditionInput
) {
updateUserProfile(input: $input, condition: $condition) {
id
fullName
city
createdAt
updatedAt
owner
}
}
;
userprofile.vue
import { Auth } from 'aws-amplify';
import { createUserProfile, updateUserProfile} from '@/graphql/mutations';
const userProfileInput={
id:userId,
fullName:'Ajit Goel',
};
await API.graphql(graphqlOperation(updateUserProfile, {input: userProfileInput}));
schema.graphql:
type UserProfile @model
@key(fields:["id"])
@auth(rules: [{allow: owner}])
{
id: String!
fullName: String
city:String
}
更新突变为运行时控制台出错:
我来帮你吧
放大推送完成后,您应该能够看到变化。请确保在尝试之前保存文件更改。
根据您的架构,城市可能会被设置为带有感叹号的强制性城市。在这种情况下,您可以删除感叹号或将城市设置为空字符串。如果特定操作需要它,您可以稍后在解析器中添加此检查。