Welcome to mirror list, hosted at ThFree Co, Russian Federation.

design_type.rb « design_management « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c0b11623063f01e87ad992fce010e19a24fd617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module Types
  module DesignManagement
    class DesignType < BaseObject
      graphql_name 'Design'
      description 'A single design'

      authorize :read_design

      alias_method :design, :object

      implements(Types::Notes::NoteableInterface)
      implements(Types::DesignManagement::DesignFields)
      implements(Types::CurrentUserTodos)
      implements(Types::TodoableInterface)

      field :web_url,
            GraphQL::Types::String,
            null: false,
            description: 'URL of the design.'

      field :versions,
            Types::DesignManagement::VersionType.connection_type,
            resolver: Resolvers::DesignManagement::VersionsResolver,
            description: "All versions related to this design ordered newest first.",
            extras: [:parent]

      # Returns a `DesignManagement::Version` for this query based on the
      # `atVersion` argument passed to a parent node if present, or otherwise
      # the most recent `Version` for the issue.
      def cached_stateful_version(parent_node)
        version_gid = Gitlab::Graphql::FindArgumentInParent.find(parent_node, :at_version)

        # Caching is scoped to an `issue_id` to allow us to cache the
        # most recent `Version` for an issue
        Gitlab::SafeRequestStore.fetch([request_cache_base_key, 'stateful_version', object.issue_id, version_gid]) do
          if version_gid
            GitlabSchema.object_from_id(version_gid, expected_type: ::DesignManagement::Version)&.sync
          else
            object.issue.design_versions.most_recent
          end
        end
      end

      def request_cache_base_key
        self.class.name
      end

      def web_url
        Gitlab::UrlBuilder.build(object)
      end
    end
  end
end