temporalio / temporalio/sdk-php

[Feature Request] Provide a typed result API

Open
#788 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
421
Forks
64
Avg merge
1d 1h
Merged PRs (30d)
11

Description

Is your feature request related to a problem? Please describe.

I would like to retrieve the result of a workflow run. The workflow method has a return type but this is not taken into account because getResult only exists on the untyped stub as the typed stub is a proxy class to the workflow and calls workflow class methods but the untyped stub doesn't have type info.

Describe the solution you'd like

There should be a higher level API than WorkflowRunInterface::getResult which can infer the type automatically from the return type of the workflow method. Since the return workflow method must be a supertype of Generator this might need the ability to handle composite types, there are multiple type libraries for example symfony/type-info although I have simply done

    $workflowReturnType = $this->temporalFactories
      ->getWorkflowStub($workflowClass)
      ->getHandlerReflection()
      ->getReturnType();
    if ($workflowReturnType instanceof \ReflectionUnionType &&
      ($types = array_diff(array_map('strval', $workflowReturnType->getTypes()), ['Generator']))) {
      return reset($types);
    }

in my workaround to the problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with WorkflowRunInterface::getResult and the workflow stub path through getWorkflowStub, getHandlerReflection, and getReturnType. Review how the Generator return type and union or composite types are represented, then define an API that infers the workflow result type automatically; done means typed workflow results can be retrieved without the workaround described.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.