Skip to content

GraphQL: epicId argument type mismatch on updateIssue mutation

When passing epicId param to updateIssue mutation, a GID type is expected (!38678 (diffs)):

mutation {
  updateIssue(input: {projectPath: "h5bp/html5-boilerplate", iid: "7", epicId: "gid://gitlab/Epic/100"}) {
    issue {
      title
      epic {
        id
      }
    }
    errors
  }
}

But we don't convert thig GID to a DB id before passing this to Issues::UpdateService which causes that epicId is treated is nil value.

A possible fix might be:

diff --git a/ee/app/graphql/ee/mutations/issues/update.rb b/ee/app/graphql/ee/mutations/issues/update.rb
index 3a1b290c98a..e353d388a3c 100644
--- a/ee/app/graphql/ee/mutations/issues/update.rb
+++ b/ee/app/graphql/ee/mutations/issues/update.rb
@@ -14,7 +14,8 @@ module EE
           argument :epic_id,
                    GraphQL::ID_TYPE,
                    required: false,
-                   description: 'The ID of the parent epic. NULL when removing the association'
+                   description: 'The ID of the parent epic. NULL when removing the association',
+                   prepare: ->(gid, ctx) { ::GitlabSchema.parse_gid(gid, expected_type: ::Epic).model_id }
         end
       end
     end

Because an exception can be raised inside Issues::UpdateService if epicId is invalid (!38678 (diffs)), we should also handle these exceptions, otherwise the response is:

{
  "errors": [
    {
      "message": "Internal server error"
    }
  ]
}

We should also add ee/spec/requests/api/graphql/mutations/issues/update_spec.rb to test API request which executes this mutation.

This is a follow-up/related to recently added epicId param - !38678 (merged) (/cc @jarka - I think I missed this in review)

Edited by Jan Provaznik