From ccb4edbca1aa7e94a76a5a8d361af02fd093e1b9 Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Mon, 18 Feb 2019 14:19:49 +1300 Subject: Improve GraphQL Authorization DSL Previously GraphQL field authorization happened like this: class ProjectType field :my_field, MyFieldType do authorize :permission end end This change allowed us to authorize like this instead: class ProjectType field :my_field, MyFieldType, authorize: :permission end A new initializer registers the `authorize` metadata keyword on GraphQL Schema Objects and Fields, and we can collect this data within the context of Instrumentation like this: field.metadata[:authorize] The previous functionality of authorize is still being used for mutations, as the #authorize method here is called at during the code that executes during the mutation, rather than when a field resolves. https://gitlab.com/gitlab-org/gitlab-ce/issues/57828 --- config/initializers/graphql.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config/initializers/graphql.rb (limited to 'config') diff --git a/config/initializers/graphql.rb b/config/initializers/graphql.rb new file mode 100644 index 00000000000..1ed93019329 --- /dev/null +++ b/config/initializers/graphql.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +GraphQL::Field.accepts_definitions(authorize: GraphQL::Define.assign_metadata_key(:authorize)) +Types::BaseField.accepts_definition(:authorize) -- cgit v1.2.3