Skip to content

Handle GlobalIDs with invalid resource names

Luke Duncalfe requested to merge ld-handle-gids-for-unknown-objects into master

What does this MR do?

A GID with an invalid model_name portion previously threw an unhandled NameError when parsed by Types::GlobalIDType due to #model_class calling constantize on the String:

GlobalID.new("gid://gitlab/invalid_name/7").model_class
# => NameError: wrong constant name invalid_name

The API client would receive our generic unhandled error response:

{
  "errors": [
    {
      "message": "Internal server error: wrong constant name <resource name>"
    }
  ]
}

This change handles this situation as a GraphQL::CoercionError and the error response for the client is:

{
  "errors": [
    {
      "message": "\"gid://gitlab/<resource name>/1\" does not represent an instance of <expected resource>"
    }
  ]
}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Luke Duncalfe

Merge request reports