Remove Graphql/GIDExpectedType cop
What does this MR do and why?
This MR removes the Graphql/GIDExpectedType
cop.
The Graphql/GIDExpectedType
cop enforces that we pass an
expected_type:
param when calling Gitlab.object_from_id
, but our
Global IDs validate that the object resolved from a Global ID matches
the model which does the same check as the expected_type:
param.
Because the check from our GlobalIDType happens earlier than the expected_type:
check (during the query validation phase rather than the resolve phase) the expected_type:
check is redundant as it's not possible to reach this point with an invalid GID.
For example, we can apply this patch to the achievementsCreate
mutation:
diff --git a/app/graphql/mutations/achievements/create.rb b/app/graphql/mutations/achievements/create.rb
index 310a653c7055..f254b7e0cc97 100644
--- a/app/graphql/mutations/achievements/create.rb
+++ b/app/graphql/mutations/achievements/create.rb
@@ -43,7 +43,7 @@ def resolve(args)
end
def find_object(id:)
- GitlabSchema.object_from_id(id, expected_type: ::Namespace)
+ GitlabSchema.object_from_id(id)
end
end
end
And execute a query where we pass a Note
GID:
mutation {
achievementsCreate(input: { namespaceId: "gid://gitlab/Note/1", name: "foo" }) {
achievement {
id
}
}
}
To see the errors from our GlobalIDType:
{
"errors": [
{
"message": "\"gid://gitlab/Note/1\" does not represent an instance of Namespace",
"locations": [
{
"line": 2,
"column": 29
}
],
"path": [
"mutation",
"achievementsCreate",
"input",
"namespaceId"
],
"extensions": {
"code": "argumentLiteralsIncompatible",
"typeName": "CoercionError"
}
}
]
}
MR acceptance checklist
-
I have evaluated the MR acceptance checklist for this MR.
Related to #417093 (closed)
Edited by Luke Duncalfe