Reputation: 4418
I have 2 (hopefully newbie) questions that I need input on, from the community:
(1) I have made changes to my application's schema.graphql file. How do i ensure that the corresponding queries.js, mutations.js, subscriptions.js files are updated? Previously these used to get updated(I think) when I ran the amplify push command but now they no longer do.
(2) How would I do a partial mutation using aws amplify? eg: if a mutation has fullName, city, how would i update fullName without passing city from the frontend application? I could be editing fullname in the first screen and city in second screen. If I do not pass city in the first screen's mutation, it gets overwritten to null.
Here's how the mutation looks like:
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
}
Error in console when update mutation is run:
Upvotes: 0
Views: 1344
Reputation: 2279
Let me try to help you
You should be able to see changes after amplify push completes. Just make sure you save file changes before trying.
Depending on your schema city may be set as mandatory with exclamation point. In that case you could either remove the exclamation point or set the city to empty string. You can add this check later in your resolver if you need it for a specific operation.
Upvotes: 1