2020-10-11 12:33:56 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-02-15 19:32:16 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using Elsa.Metadata;
|
|
|
|
|
|
using Elsa.Models;
|
2020-10-10 15:13:52 +00:00
|
|
|
|
using Elsa.Queries;
|
2020-02-15 19:32:16 +00:00
|
|
|
|
using Elsa.Server.GraphQL.Models;
|
|
|
|
|
|
using Elsa.Services;
|
|
|
|
|
|
using HotChocolate;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Server.GraphQL
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Query
|
|
|
|
|
|
{
|
|
|
|
|
|
public IEnumerable<ActivityDescriptor> GetActivityDescriptors(
|
2020-10-11 20:02:14 +00:00
|
|
|
|
[Service] IActivityActivator activityActivator,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
[Service] IActivityDescriber describer) =>
|
2020-10-11 20:02:14 +00:00
|
|
|
|
activityActivator.GetActivityTypes().Select(describer.Describe).ToList();
|
2020-02-15 19:32:16 +00:00
|
|
|
|
|
|
|
|
|
|
public ActivityDescriptor? GetActivityDescriptor(
|
2020-10-11 20:02:14 +00:00
|
|
|
|
[Service] IActivityActivator activityActivator,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
[Service] IActivityDescriber describer,
|
|
|
|
|
|
string typeName)
|
|
|
|
|
|
{
|
2020-10-11 20:02:14 +00:00
|
|
|
|
var type = activityActivator.GetActivityType(typeName);
|
2020-02-15 19:32:16 +00:00
|
|
|
|
|
|
|
|
|
|
return type == null ? default : describer.Describe(type);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-09 20:26:19 +00:00
|
|
|
|
public async Task<IEnumerable<WorkflowDefinition>> GetWorkflowDefinitions(
|
2020-02-15 19:32:16 +00:00
|
|
|
|
VersionOptionsInput? version,
|
2020-10-11 12:33:18 +00:00
|
|
|
|
[Service] IWorkflowDefinitionManager manager,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
[Service] IMapper mapper,
|
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
var mappedVersion = mapper.Map<VersionOptions?>(version);
|
2020-10-11 12:33:18 +00:00
|
|
|
|
return await manager.ListAsync(mappedVersion ?? VersionOptions.Latest, cancellationToken);
|
2020-02-15 19:32:16 +00:00
|
|
|
|
}
|
2020-10-10 15:13:52 +00:00
|
|
|
|
|
|
|
|
|
|
public async Task<WorkflowDefinition?> GetWorkflowDefinition(
|
|
|
|
|
|
string? workflowDefinitionVersionId,
|
|
|
|
|
|
string? workflowDefinitionId,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
VersionOptionsInput? version,
|
2020-10-11 12:33:18 +00:00
|
|
|
|
[Service] IWorkflowDefinitionManager manager,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
[Service] IMapper mapper,
|
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2020-10-10 15:13:52 +00:00
|
|
|
|
if (workflowDefinitionVersionId != null)
|
2020-10-11 12:33:18 +00:00
|
|
|
|
return await manager.GetByVersionIdAsync(workflowDefinitionVersionId, cancellationToken);
|
2020-10-10 15:13:52 +00:00
|
|
|
|
|
2020-02-15 19:32:16 +00:00
|
|
|
|
var mappedVersion = mapper.Map<VersionOptions?>(version);
|
2020-10-10 15:13:52 +00:00
|
|
|
|
|
2020-10-11 12:33:18 +00:00
|
|
|
|
return await manager.GetAsync(
|
2020-10-10 15:13:52 +00:00
|
|
|
|
workflowDefinitionId!,
|
|
|
|
|
|
mappedVersion ?? VersionOptions.Latest,
|
|
|
|
|
|
cancellationToken);
|
2020-02-15 19:32:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<WorkflowInstance>> GetWorkflowInstances(
|
2020-10-10 15:13:52 +00:00
|
|
|
|
string definitionId,
|
2020-02-15 19:32:16 +00:00
|
|
|
|
WorkflowStatus? status,
|
2020-10-11 12:33:18 +00:00
|
|
|
|
[Service] IWorkflowInstanceManager manager,
|
|
|
|
|
|
CancellationToken cancellationToken) =>
|
|
|
|
|
|
status == null
|
|
|
|
|
|
? await manager.ListByDefinitionAsync(definitionId, cancellationToken)
|
|
|
|
|
|
: await manager.ListByDefinitionAndStatusAsync(definitionId, status.Value, cancellationToken);
|
2020-10-10 15:13:52 +00:00
|
|
|
|
|
|
|
|
|
|
public async Task<WorkflowInstance?> GetWorkflowInstance(
|
2020-02-15 19:32:16 +00:00
|
|
|
|
string id,
|
2020-10-11 12:33:18 +00:00
|
|
|
|
[Service] IWorkflowInstanceManager manager,
|
|
|
|
|
|
CancellationToken cancellationToken) =>
|
|
|
|
|
|
await manager.GetByWorkflowInstanceIdAsync(id, cancellationToken);
|
2020-02-15 19:32:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|