Skip to content

GraphQL API for listing all workflows for a user

What does this MR do and why?

The MR adds a new GraphQL endpoint to return all workflows belonging to the current user.

This MR adds a new scope Ai::DuoWorkflows::Workflow.for_user. A sample query of this scope is as follows:

SELECT "duo_workflows_workflows".* FROM "duo_workflows_workflows" WHERE "duo_workflows_workflows"."user_id" = 1

Query plan from postgres.ai.

Note that there are no workflows in the production thus this query returns 0 rows.

 Seq Scan on public.duo_workflows_workflows  (cost=0.00..0.00 rows=1 width=42) (actual time=0.027..0.027 rows=0 loops=1)
   Filter: (duo_workflows_workflows.user_id = 1614863)
   Rows Removed by Filter: 0
   I/O Timings: read=0.000 write=0.000

Recommendations: Looks good

Summary

Time: 0.796 ms  
  - planning: 0.722 ms  
  - execution: 0.074 ms  
    - I/O read: 0.000 ms  
    - I/O write: 0.000 ms  
  
Shared buffers:  
  - hits: 0 from the buffer pool  
  - reads: 0 from the OS file cache, including disk I/O  
  - dirtied: 0  
  - writes: 0  

Explain in rails console from local environment

I'm also adding this as there are no workflow records in postgres.ai

Ai::DuoWorkflows::Workflow.for_user(1).explain
  Ai::DuoWorkflows::Workflow Load (1.0ms)  SELECT "duo_workflows_workflows".* FROM "duo_workflows_workflows" WHERE "duo_workflows_workflows"."user_id" = 1 
=> EXPLAIN for: SELECT "duo_workflows_workflows".* FROM "duo_workflows_workflows" WHERE "duo_workflows_workflows"."user_id" = 1 
                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
 Index Scan using index_duo_workflows_workflows_on_user_id on duo_workflows_workflows  (cost=0.15..6.26 rows=6 width=42)
   Index Cond: (user_id = 1)
(2 rows)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshot_2024-07-10_at_16.46.44

How to set up and validate locally

  1. Enable FF start_duo_workflows
  2. Create a duo workflow for a project you have developer access
curl -XPOST -i http://gdk.test:3000/api/v4/ai/duo_workflows/workflows\?private_token\=[YOUR_TOKEN]\&project_id\=[PROJECT_ID]
  1. Visit http://gdk.test:3000/-/graphql-explorer
  2. Run the following query.
query getDuoWorkflowWorkflows {
  duoWorkflowWorkflows {
    edges {
      node {
        id,
        projectId,
        userId,
        humanStatus,
        createdAt,
        updatedAt
      }
    }
  }
}

Related to #469451 (closed)

Edited by Halil Coban

Merge request reports

Loading