0

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:

enter image description here

Ajit Goel
  • 4,180
  • 7
  • 59
  • 107

1 Answers1

1

Let me try to help you

  1. You should be able to see changes after amplify push completes. Just make sure you save file changes before trying.

  2. 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.

Gerard Sans
  • 2,269
  • 1
  • 13
  • 13
  • issue 1 is not working for sure. wrt to the second issue, I could be editing fullname in the first screen and city in second screen. In this case, how would I write my mutation in each of the screens? If I do not pass city in the first screen's mutation, it gets overwritten to null. – Ajit Goel Jul 23 '20 at 13:37
  • I see. I also mentioned to pass city as empty string. Have you tried that? – Gerard Sans Jul 25 '20 at 18:35
  • You may need different logic to cover creating new user profiles or updating them. For new ones I don't see any issue as all fields are new/empty. For updating an existing profile you will have to query current values and use them in your partial mutations. – Gerard Sans Jul 25 '20 at 18:40
  • Thanks @gerard sans, grapql needs definatley more work than what initially i thought was needed. – Ajit Goel Jul 25 '20 at 19:40