Skip to content

Commit

Permalink
get samples through SamplesWorkflowExecutions instead of directly
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyThiessen committed Nov 26, 2024
1 parent a0b9943 commit 0230b2e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/graphql/resolvers/samples_workflow_executions_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 32 additions & 22 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions app/graphql/types/samples_workflow_execution_type.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions app/graphql/types/workflow_execution_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 9 additions & 13 deletions test/graphql/workflow_executions_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ class WorkflowExecutionsQueryTest < ActiveSupport::TestCase
nodes {
id
runId
samples {
edges {
node {
id
}
samplesWorkflowExecutions {
sample {
id
}
}
}
Expand Down Expand Up @@ -53,11 +51,9 @@ class WorkflowExecutionsQueryTest < ActiveSupport::TestCase
workflowType
workflowTypeVersion
workflowUrl
samples {
edges {
node {
id
}
samplesWorkflowExecutions {
sample {
id
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0230b2e

Please sign in to comment.