GraphQL: Remove use of resolve procs from type definitions
The new GraphQL interpreter does not support resolve procs for field definitions (https://graphql-ruby.org/queries/interpreter.html#compatibility).
We can remove these as a step to migrating to the new interpreter.
Typical example:
field :user,
Types::UserType,
null: false,
description: 'The user who awarded the emoji',
resolve: -> (award_emoji, _args, _context) {
Gitlab::Graphql::Loaders::BatchModelLoader.new(User, award_emoji.user_id).find
}
description: 'The user who awarded the emoji'
becomes instead
field :user,
Types::UserType,
null: false,
description: 'The user who awarded the emoji'
def user
Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.user_id).find
end
Notice that the resolve is now a method of the same name as the field, and object
and context
are automatically available in the new method.
Edited by Brett Walker