connect service function to resolver

This commit is contained in:
Charles Driesler
2024-05-31 11:24:48 +01:00
parent 7fb810e89b
commit 26fa2d96ac
7 changed files with 171 additions and 5 deletions
@@ -1825,6 +1825,7 @@ export type ProjectAutomationMutations = {
create: Automation;
createRevision: AutomationRevision;
createTestAutomation: Automation;
createTestAutomationRun: TestAutomationRun;
/**
* Trigger an automation with a fake "version created" trigger. The "version created" will
* just refer to the last version of the model.
@@ -1849,6 +1850,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = {
};
export type ProjectAutomationMutationsCreateTestAutomationRunArgs = {
automationId: Scalars['ID'];
};
export type ProjectAutomationMutationsTriggerArgs = {
automationId: Scalars['ID'];
};
@@ -3030,6 +3036,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = {
target: ViewerUpdateTrackingTarget;
};
export type TestAutomationRun = {
__typename?: 'TestAutomationRun';
automationRunId: Scalars['String'];
functionRunId: Scalars['String'];
triggers: Array<TestAutomationRunTrigger>;
};
export type TestAutomationRunTrigger = {
__typename?: 'TestAutomationRunTrigger';
payload: TestAutomationRunTriggerPayload;
triggerType: Scalars['String'];
};
export type TestAutomationRunTriggerPayload = {
__typename?: 'TestAutomationRunTriggerPayload';
modelId: Scalars['String'];
versionId: Scalars['String'];
};
export type TokenResourceIdentifier = {
__typename?: 'TokenResourceIdentifier';
id: Scalars['String'];
@@ -297,7 +297,7 @@ type ProjectAutomationMutations {
"""
trigger(automationId: ID!): Boolean!
createTestAutomation(input: ProjectTestAutomationCreateInput!): Automation!
createTestAutomationRun(automationId: ID!): String!
createTestAutomationRun(automationId: ID!): TestAutomationRun!
}
extend type ProjectMutations {
@@ -388,3 +388,19 @@ extend type Subscription {
"""
projectAutomationsUpdated(projectId: String!): ProjectAutomationsUpdatedMessage!
}
type TestAutomationRun {
automationRunId: String!
functionRunId: String!
triggers: [TestAutomationRunTrigger!]!
}
type TestAutomationRunTrigger {
payload: TestAutomationRunTriggerPayload!
triggerType: String!
}
type TestAutomationRunTriggerPayload {
modelId: String!
versionId: String!
}
@@ -13,7 +13,9 @@ import {
getAutomationRunsItems,
getAutomationRunsTotalCount,
getAutomationTriggerDefinitions,
getFullAutomationRevisionMetadata,
getFunctionRun,
getLatestAutomationRevision,
getLatestVersionAutomationRuns,
getProjectAutomationsItems,
getProjectAutomationsTotalCount,
@@ -61,6 +63,7 @@ import {
getBranchesByIds
} from '@/modules/core/repositories/branches'
import {
createTestAutomationRun,
manuallyTriggerAutomation,
triggerAutomationRevisionRun
} from '@/modules/automate/services/trigger'
@@ -520,6 +523,23 @@ export = (FF_AUTOMATE_MODULE_ENABLED
userId: ctx.userId!,
userResourceAccessRules: ctx.resourceAccessRules
})
},
async createTestAutomationRun(parent, { automationId }, ctx) {
const create = createTestAutomationRun({
getEncryptionKeyPairFor,
getFunctionInputDecryptor: getFunctionInputDecryptor({
buildDecryptor
}),
getAutomation,
getLatestAutomationRevision,
getFullAutomationRevisionMetadata
})
return await create({
projectId: parent.projectId,
automationId,
userId: ctx.userId!
})
}
},
Query: {
@@ -511,13 +511,15 @@ export type CreateTestAutomationRunDeps = {
export const createTestAutomationRun =
(deps: CreateTestAutomationRunDeps) =>
async (params: { automationId: string; userId: string }) => {
async (params: { projectId: string; automationId: string; userId: string }) => {
const {
getAutomation,
getLatestAutomationRevision,
getFullAutomationRevisionMetadata
} = deps
const { automationId, userId } = params
const { projectId, automationId, userId } = params
await validateStreamAccess(userId, projectId, Roles.Stream.Owner)
const automationRecord = await getAutomation({ automationId })
@@ -531,8 +533,6 @@ export const createTestAutomationRun =
)
}
await validateStreamAccess(userId, automationRecord.projectId, Roles.Stream.Owner)
const { id: automationRevisionId } =
(await getLatestAutomationRevision({ automationId })) ?? {}
@@ -579,6 +579,7 @@ export const createTestAutomationRun =
})
await upsertAutomationRun(automationRunRecord)
// TODO: Test functions only support one function run per automation
const functionRunId = automationRunRecord.functionRuns[0].id
return {
@@ -1839,6 +1839,7 @@ export type ProjectAutomationMutations = {
create: Automation;
createRevision: AutomationRevision;
createTestAutomation: Automation;
createTestAutomationRun: TestAutomationRun;
/**
* Trigger an automation with a fake "version created" trigger. The "version created" will
* just refer to the last version of the model.
@@ -1863,6 +1864,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = {
};
export type ProjectAutomationMutationsCreateTestAutomationRunArgs = {
automationId: Scalars['ID'];
};
export type ProjectAutomationMutationsTriggerArgs = {
automationId: Scalars['ID'];
};
@@ -3044,6 +3050,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = {
target: ViewerUpdateTrackingTarget;
};
export type TestAutomationRun = {
__typename?: 'TestAutomationRun';
automationRunId: Scalars['String'];
functionRunId: Scalars['String'];
triggers: Array<TestAutomationRunTrigger>;
};
export type TestAutomationRunTrigger = {
__typename?: 'TestAutomationRunTrigger';
payload: TestAutomationRunTriggerPayload;
triggerType: Scalars['String'];
};
export type TestAutomationRunTriggerPayload = {
__typename?: 'TestAutomationRunTriggerPayload';
modelId: Scalars['String'];
versionId: Scalars['String'];
};
export type TokenResourceIdentifier = {
__typename?: 'TokenResourceIdentifier';
id: Scalars['String'];
@@ -3734,6 +3759,9 @@ export type ResolversTypes = {
StreamUpdatePermissionInput: StreamUpdatePermissionInput;
String: ResolverTypeWrapper<Scalars['String']>;
Subscription: ResolverTypeWrapper<{}>;
TestAutomationRun: ResolverTypeWrapper<TestAutomationRun>;
TestAutomationRunTrigger: ResolverTypeWrapper<TestAutomationRunTrigger>;
TestAutomationRunTriggerPayload: ResolverTypeWrapper<TestAutomationRunTriggerPayload>;
TokenResourceIdentifier: ResolverTypeWrapper<TokenResourceIdentifier>;
TokenResourceIdentifierInput: TokenResourceIdentifierInput;
TokenResourceIdentifierType: TokenResourceIdentifierType;
@@ -3938,6 +3966,9 @@ export type ResolversParentTypes = {
StreamUpdatePermissionInput: StreamUpdatePermissionInput;
String: Scalars['String'];
Subscription: {};
TestAutomationRun: TestAutomationRun;
TestAutomationRunTrigger: TestAutomationRunTrigger;
TestAutomationRunTriggerPayload: TestAutomationRunTriggerPayload;
TokenResourceIdentifier: TokenResourceIdentifier;
TokenResourceIdentifierInput: TokenResourceIdentifierInput;
TriggeredAutomationsStatus: TriggeredAutomationsStatusGraphQLReturn;
@@ -4702,6 +4733,7 @@ export type ProjectAutomationMutationsResolvers<ContextType = GraphQLContext, Pa
create?: Resolver<ResolversTypes['Automation'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsCreateArgs, 'input'>>;
createRevision?: Resolver<ResolversTypes['AutomationRevision'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsCreateRevisionArgs, 'input'>>;
createTestAutomation?: Resolver<ResolversTypes['Automation'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsCreateTestAutomationArgs, 'input'>>;
createTestAutomationRun?: Resolver<ResolversTypes['TestAutomationRun'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsCreateTestAutomationRunArgs, 'automationId'>>;
trigger?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsTriggerArgs, 'automationId'>>;
update?: Resolver<ResolversTypes['Automation'], ParentType, ContextType, RequireFields<ProjectAutomationMutationsUpdateArgs, 'input'>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
@@ -5072,6 +5104,25 @@ export type SubscriptionResolvers<ContextType = GraphQLContext, ParentType exten
viewerUserActivityBroadcasted?: SubscriptionResolver<ResolversTypes['ViewerUserActivityMessage'], "viewerUserActivityBroadcasted", ParentType, ContextType, RequireFields<SubscriptionViewerUserActivityBroadcastedArgs, 'target'>>;
};
export type TestAutomationRunResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['TestAutomationRun'] = ResolversParentTypes['TestAutomationRun']> = {
automationRunId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
functionRunId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
triggers?: Resolver<Array<ResolversTypes['TestAutomationRunTrigger']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
export type TestAutomationRunTriggerResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['TestAutomationRunTrigger'] = ResolversParentTypes['TestAutomationRunTrigger']> = {
payload?: Resolver<ResolversTypes['TestAutomationRunTriggerPayload'], ParentType, ContextType>;
triggerType?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
export type TestAutomationRunTriggerPayloadResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['TestAutomationRunTriggerPayload'] = ResolversParentTypes['TestAutomationRunTriggerPayload']> = {
modelId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
versionId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
export type TokenResourceIdentifierResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['TokenResourceIdentifier'] = ResolversParentTypes['TokenResourceIdentifier']> = {
id?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
type?: Resolver<ResolversTypes['TokenResourceIdentifierType'], ParentType, ContextType>;
@@ -5346,6 +5397,9 @@ export type Resolvers<ContextType = GraphQLContext> = {
StreamCollaborator?: StreamCollaboratorResolvers<ContextType>;
StreamCollection?: StreamCollectionResolvers<ContextType>;
Subscription?: SubscriptionResolvers<ContextType>;
TestAutomationRun?: TestAutomationRunResolvers<ContextType>;
TestAutomationRunTrigger?: TestAutomationRunTriggerResolvers<ContextType>;
TestAutomationRunTriggerPayload?: TestAutomationRunTriggerPayloadResolvers<ContextType>;
TokenResourceIdentifier?: TokenResourceIdentifierResolvers<ContextType>;
TriggeredAutomationsStatus?: TriggeredAutomationsStatusResolvers<ContextType>;
User?: UserResolvers<ContextType>;
@@ -1828,6 +1828,7 @@ export type ProjectAutomationMutations = {
create: Automation;
createRevision: AutomationRevision;
createTestAutomation: Automation;
createTestAutomationRun: TestAutomationRun;
/**
* Trigger an automation with a fake "version created" trigger. The "version created" will
* just refer to the last version of the model.
@@ -1852,6 +1853,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = {
};
export type ProjectAutomationMutationsCreateTestAutomationRunArgs = {
automationId: Scalars['ID'];
};
export type ProjectAutomationMutationsTriggerArgs = {
automationId: Scalars['ID'];
};
@@ -3033,6 +3039,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = {
target: ViewerUpdateTrackingTarget;
};
export type TestAutomationRun = {
__typename?: 'TestAutomationRun';
automationRunId: Scalars['String'];
functionRunId: Scalars['String'];
triggers: Array<TestAutomationRunTrigger>;
};
export type TestAutomationRunTrigger = {
__typename?: 'TestAutomationRunTrigger';
payload: TestAutomationRunTriggerPayload;
triggerType: Scalars['String'];
};
export type TestAutomationRunTriggerPayload = {
__typename?: 'TestAutomationRunTriggerPayload';
modelId: Scalars['String'];
versionId: Scalars['String'];
};
export type TokenResourceIdentifier = {
__typename?: 'TokenResourceIdentifier';
id: Scalars['String'];
@@ -1829,6 +1829,7 @@ export type ProjectAutomationMutations = {
create: Automation;
createRevision: AutomationRevision;
createTestAutomation: Automation;
createTestAutomationRun: TestAutomationRun;
/**
* Trigger an automation with a fake "version created" trigger. The "version created" will
* just refer to the last version of the model.
@@ -1853,6 +1854,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = {
};
export type ProjectAutomationMutationsCreateTestAutomationRunArgs = {
automationId: Scalars['ID'];
};
export type ProjectAutomationMutationsTriggerArgs = {
automationId: Scalars['ID'];
};
@@ -3034,6 +3040,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = {
target: ViewerUpdateTrackingTarget;
};
export type TestAutomationRun = {
__typename?: 'TestAutomationRun';
automationRunId: Scalars['String'];
functionRunId: Scalars['String'];
triggers: Array<TestAutomationRunTrigger>;
};
export type TestAutomationRunTrigger = {
__typename?: 'TestAutomationRunTrigger';
payload: TestAutomationRunTriggerPayload;
triggerType: Scalars['String'];
};
export type TestAutomationRunTriggerPayload = {
__typename?: 'TestAutomationRunTriggerPayload';
modelId: Scalars['String'];
versionId: Scalars['String'];
};
export type TokenResourceIdentifier = {
__typename?: 'TokenResourceIdentifier';
id: Scalars['String'];