【发布时间】:2020-11-12 19:01:23
【问题描述】:
我有 2 个(希望是新手)问题需要来自社区的意见:
(1) 我对应用程序的 schema.graphql 文件进行了更改。如何确保更新相应的 queries.js、mutations.js、subscriptions.js 文件?以前这些在我运行放大推送命令时会更新(我认为),但现在它们不再更新了。
(2) 如何使用 aws amplify 进行部分突变?例如:如果突变具有全名、城市,我将如何在不从前端应用程序传递城市的情况下更新全名? 我可以在第一个屏幕中编辑全名,在第二个屏幕中编辑城市。如果我没有在第一个屏幕的突变中通过 city,它会被覆盖为 null。
这是突变的样子:
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
}
运行更新突变时控制台出错:
【问题讨论】:
标签: vue.js graphql aws-amplify graphql-js aws-amplify-cli