From 0230b2e1012bae8b7abee593ba3f8251787658dc Mon Sep 17 00:00:00 2001 From: Jeffrey Thiessen Date: Tue, 26 Nov 2024 16:20:09 -0600 Subject: [PATCH] get samples through SamplesWorkflowExecutions instead of directly --- .../samples_workflow_executions_resolver.rb | 4 +- app/graphql/schema.graphql | 54 +++++++++++-------- .../types/samples_workflow_execution_type.rb | 21 ++++++++ app/graphql/types/workflow_execution_type.rb | 6 +-- .../graphql/workflow_executions_query_test.rb | 22 ++++---- 5 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 app/graphql/types/samples_workflow_execution_type.rb diff --git a/app/graphql/resolvers/samples_workflow_executions_resolver.rb b/app/graphql/resolvers/samples_workflow_executions_resolver.rb index 13e9f1b4a7..0abb206b25 100644 --- a/app/graphql/resolvers/samples_workflow_executions_resolver.rb +++ b/app/graphql/resolvers/samples_workflow_executions_resolver.rb @@ -3,13 +3,13 @@ module Resolvers # Samples WorkflowExecutions Resolver class SamplesWorkflowExecutionsResolver < BaseResolver - type Types::SampleType, null: true + type Types::SamplesWorkflowExecutionType, null: true alias workflow_execution object def resolve scope = workflow_execution - scope.samples + scope.samples_workflow_executions end end end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index e0630e4036..305cc5985e 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -2827,6 +2827,36 @@ enum SampleOrderField { updated_at } +""" +A SamplesWorkflowExecition +""" +type SamplesWorkflowExecution implements Node { + """ + Datetime of creation. + """ + createdAt: ISO8601DateTime! + + """ + ID of the object. + """ + id: ID! + + """ + Sample + """ + sample: Sample + + """ + Datetime of last update. + """ + updatedAt: ISO8601DateTime! + + """ + WorkflowExecution + """ + workflowExecution: WorkflowExecution +} + """ Autogenerated input type of TransferSamples """ @@ -3027,29 +3057,9 @@ type WorkflowExecution implements Node { runId: String """ - Samples on the workflow execution + SamplesWorkflowExecutions on the workflow execution """ - samples( - """ - Returns the elements in the list that come after the specified cursor. - """ - after: String - - """ - Returns the elements in the list that come before the specified cursor. - """ - before: String - - """ - Returns the first _n_ elements from the list. - """ - first: Int - - """ - Returns the last _n_ elements from the list. - """ - last: Int - ): SampleConnection + samplesWorkflowExecutions: [SamplesWorkflowExecution!] """ WorkflowExecution state diff --git a/app/graphql/types/samples_workflow_execution_type.rb b/app/graphql/types/samples_workflow_execution_type.rb new file mode 100644 index 0000000000..df81468fe8 --- /dev/null +++ b/app/graphql/types/samples_workflow_execution_type.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Types + # SamplesWorkflowExecition Type + class SamplesWorkflowExecutionType < Types::BaseType + implements GraphQL::Types::Relay::Node + description 'A SamplesWorkflowExecition' + + field :sample, Types::SampleType, null: true, description: 'Sample' + field :workflow_execution, Types::WorkflowExecutionType, null: true, description: 'WorkflowExecution' + + def self.authorized?(object, context) + super && + allowed_to?( + :read?, + object.workflow_execution, + context: { user: context[:current_user], token: context[:token] } + ) + end + end +end diff --git a/app/graphql/types/workflow_execution_type.rb b/app/graphql/types/workflow_execution_type.rb index d1dc298a56..6e3a99c508 100644 --- a/app/graphql/types/workflow_execution_type.rb +++ b/app/graphql/types/workflow_execution_type.rb @@ -18,10 +18,10 @@ class WorkflowExecutionType < Types::BaseObject field :name, String, null: true, description: 'WorkflowExecution name' field :project, ProjectType, null: true, description: 'Project, if the workflow belongs to a project namespace' field :run_id, String, null: true, description: 'WorkflowExecution run id' - field :samples, - SampleType.connection_type, + field :samples_workflow_executions, + [SamplesWorkflowExecutionType], null: true, - description: 'Samples on the workflow execution', + description: 'SamplesWorkflowExecutions on the workflow execution', complexity: 5, resolver: Resolvers::SamplesWorkflowExecutionsResolver field :state, String, null: true, description: 'WorkflowExecution state' diff --git a/test/graphql/workflow_executions_query_test.rb b/test/graphql/workflow_executions_query_test.rb index 0efd2d9af8..274dacf2e4 100644 --- a/test/graphql/workflow_executions_query_test.rb +++ b/test/graphql/workflow_executions_query_test.rb @@ -9,11 +9,9 @@ class WorkflowExecutionsQueryTest < ActiveSupport::TestCase nodes { id runId - samples { - edges { - node { - id - } + samplesWorkflowExecutions { + sample { + id } } } @@ -53,11 +51,9 @@ class WorkflowExecutionsQueryTest < ActiveSupport::TestCase workflowType workflowTypeVersion workflowUrl - samples { - edges { - node { - id - } + samplesWorkflowExecutions { + sample { + id } } } @@ -112,15 +108,15 @@ def setup )['data'] workflow_execution_id = prelim_query['workflowExecutions']['nodes'][0]['id'] - sample_id = prelim_query['workflowExecutions']['nodes'][0]['samples']['edges'][0]['node']['id'] + sample_id = prelim_query['workflowExecutions']['nodes'][0]['samplesWorkflowExecutions'][0]['sample']['id'] result = IridaSchema.execute(WORKFLOW_EXECUTIONS_NODE_QUERY, context: { current_user: @user }, variables: { workflow_execution_id: }) data = result['data']['node'] - assert_not_empty data['samples']['edges'], 'workflow execution samples resolver should work' - assert_equal sample_id, data['samples']['edges'][0]['node']['id'], 'sample id should match' + assert_not_empty data['samplesWorkflowExecutions'], 'workflow execution samples resolver should work' + assert_equal sample_id, data['samplesWorkflowExecutions'][0]['sample']['id'], 'sample id should match' end test 'workflow executions nodes query for metadata though resolver should work' do