Project

General

Profile

Bug #33647

GraphQL response should return valid attribute values

Added by Ondřej Pražák 10 months ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

When we are updating models via GraphQL, we assign new attribute values to the model and save (BaseMutation#save_object).
If there are validation errors, the model with invalid attribute values is used for response. This is causing problems in UI with as Apollo detects a change in an attribute and places the new (invalid) value into its cache. To leverage Apollo's automatic cache updates, we should return the persisted value, not the assigned and invalid.

Steps to reproduce:

variables = { id: model_global_id, name: '' }

mutation UpdateModelMutation($id: ID!, $name: String) {
  updateModel(input: { id: $id, name: $name }) {
    model {
      id
      name
    }
    errors {
      path
      message
    }
  }
}

Expected Result:

{
  updateModel {
    model {
      id: 'very_long_global_id',
      name: 'My model'
    },
    errors: [{
     path: ["attributes", "name"],
     message: "can't be blank" 
   }]
  }
}

Actual Result:

{
  updateModel {
    model {
      id: 'very_long_global_id',
      name: ''
    },
    errors: [{
     path: ["attributes", "name"],
     message: "can't be blank" 
   }]
  }
}

Associated revisions

Revision d0f5a61b (diff)
Added by Ondřej Pražák 10 months ago

Fixes #33647 - Return persisted attrs on edit mutation

History

#1 Updated by The Foreman Bot 10 months ago

  • Assignee set to Ondřej Pražák
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/8819 added

#2 Updated by The Foreman Bot 10 months ago

  • Fixed in Releases 3.1.0 added

#3 Updated by Ondřej Pražák 10 months ago

  • Status changed from Ready For Testing to Closed

#4 Updated by Amit Upadhye 9 months ago

  • Category set to API

Also available in: Atom PDF