Skip to content

Commit

Permalink
fix graphql resolver bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed Dec 14, 2023
1 parent d7059df commit 8918eac
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
7 changes: 7 additions & 0 deletions modules/vf-graphql-holochain/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ProposedIntent from './proposedIntent.js'
import Agreement from './agreement.js'
import Plan from './plan.js'
import Agent from './agent.js'
import RecipeFlow from './recipeFlow.js'
import RecipeProcess from './recipeProcess.js'

// generic deletion calling format used by all mutations
export type deleteHandler = (root: any, args: ByRevision) => Promise<boolean>
Expand All @@ -41,6 +43,7 @@ export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DN
const hasProposal = -1 !== enabledVFModules.indexOf(VfModule.Proposal)
const hasAgreement = -1 !== enabledVFModules.indexOf(VfModule.Agreement)
const hasPlan = -1 !== enabledVFModules.indexOf(VfModule.Plan)
const hasRecipe = -1 !== enabledVFModules.indexOf(VfModule.Recipe)

return Object.assign(
(hasMeasurement ? { ...Unit(dnaConfig, conductorUri) } : {}),
Expand Down Expand Up @@ -79,5 +82,9 @@ export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DN
(hasAgreement ? { ...Agreement(dnaConfig, conductorUri) } : {}),
(hasPlan ? { ...Plan(dnaConfig, conductorUri) } : {}),
(hasAgent ? { ...Agent(dnaConfig, conductorUri) } : {}),
(hasRecipe ? {
...RecipeFlow(dnaConfig, conductorUri),
...RecipeProcess(dnaConfig, conductorUri),
} : {}),
)
}
7 changes: 7 additions & 0 deletions modules/vf-graphql-holochain/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Satisfaction from './satisfaction.js'
import Proposal from './proposal.js'
import Agreement from './agreement.js'
import Plan from './plan.js'
import RecipeFlow from './recipeFlow.js'
import RecipeProcess from './recipeFlow.js'

export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DNAIdMappings, conductorUri: string) => {
const hasAgent = -1 !== enabledVFModules.indexOf(VfModule.Agent)
Expand All @@ -38,6 +40,7 @@ export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DN
const hasProposal = -1 !== enabledVFModules.indexOf(VfModule.Proposal)
const hasAgreement = -1 !== enabledVFModules.indexOf(VfModule.Agreement)
const hasPlan = -1 !== enabledVFModules.indexOf(VfModule.Plan)
const hasRecipe = -1 !== enabledVFModules.indexOf(VfModule.Recipe)

return Object.assign(
(hasAction ? {
Expand Down Expand Up @@ -73,5 +76,9 @@ export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DN
(hasProposal ? { ...Proposal(dnaConfig, conductorUri) } : {}),
(hasAgreement ? { ...Agreement(dnaConfig, conductorUri) } : {}),
(hasPlan ? { ...Plan(dnaConfig, conductorUri) } : {}),
(hasRecipe ? {
...RecipeFlow(dnaConfig, conductorUri),
...RecipeProcess(dnaConfig, conductorUri)
} : {}),
)
}
4 changes: 2 additions & 2 deletions modules/vf-graphql-holochain/queries/recipeFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { PagingParams } from '../resolvers/zomeSearchInputTypes.js'

export default (dnaConfig: DNAIdMappings, conductorUri: string) => {
const readOne = mapZomeFn<ReadParams, RecipeFlowResponse>(dnaConfig, conductorUri, 'planning', 'recipe_flow', 'get_recipe_flow')
const readAll = mapZomeFn<PagingParams, RecipeFlowConnection>(dnaConfig, conductorUri, 'planning', 'recipe_flow_index', 'read_all_recipe_flows')
const readOne = mapZomeFn<ReadParams, RecipeFlowResponse>(dnaConfig, conductorUri, 'recipe', 'recipe_flow', 'get_recipe_flow')
const readAll = mapZomeFn<PagingParams, RecipeFlowConnection>(dnaConfig, conductorUri, 'recipe', 'recipe_flow_index', 'read_all_recipe_flows')

return {
recipeFlow: async (root, args): Promise<RecipeFlow> => {
Expand Down
8 changes: 8 additions & 0 deletions modules/vf-graphql-holochain/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import ProposedIntent from './proposedIntent.js'
import Agreement from './agreement.js'
import Plan from './plan.js'

import RecipeFlow from './recipeFlow.js'
import RecipeProcess from './recipeProcess.js'

// union type disambiguation
const EventOrCommitment = {
__resolveType: (obj, ctx, info) => obj.__typename,
Expand Down Expand Up @@ -78,6 +81,7 @@ const generateResolvers = async (options: ResolverOptions) => {
const hasProposal = -1 !== enabledVFModules.indexOf(VfModule.Proposal)
const hasAgreement = -1 !== enabledVFModules.indexOf(VfModule.Agreement)
const hasPlan = -1 !== enabledVFModules.indexOf(VfModule.Plan)
const hasRecipe = -1 !== enabledVFModules.indexOf(VfModule.Recipe)

// prefetch connection for this API schema
// and also this makes calls to the admin conductor to authorize a set of signing
Expand Down Expand Up @@ -141,6 +145,10 @@ const generateResolvers = async (options: ResolverOptions) => {
} : {}),
(hasAgreement ? { Agreement: Agreement(enabledVFModules, dnaConfig, conductorUri) } : {}),
(hasPlan ? { Plan: Plan(enabledVFModules, dnaConfig, conductorUri) } : {}),
(hasRecipe ? {
RecipeFlow: RecipeFlow(enabledVFModules, dnaConfig, conductorUri),
RecipeProcess: RecipeProcess(enabledVFModules, dnaConfig, conductorUri),
} : {}),
)
}

Expand Down
43 changes: 17 additions & 26 deletions modules/vf-graphql-holochain/resolvers/recipeFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,35 @@ const extractProposedIntent = (data): ProposedIntent => data.proposedIntent

export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DNAIdMappings, conductorUri: string) => {
const hasResourceSpecification = -1 !== enabledVFModules.indexOf(VfModule.ResourceSpecification)
const hasProcessSpecification = -1 !== enabledVFModules.indexOf(VfModule.ProcessSpecification)
const hasAction = -1 !== enabledVFModules.indexOf(VfModule.Action)
const hasRecipeInput = -1 !== enabledVFModules.indexOf(VfModule.RecipeProcess)
const hasRecipeOutput = -1 !== enabledVFModules.indexOf(VfModule.RecipeProcess)
// const hasProcessSpecification = -1 !== enabledVFModules.indexOf(VfModule.ProcessSpecification)
// const hasAction = -1 !== enabledVFModules.indexOf(VfModule.Action)
const hasHistory = -1 !== enabledVFModules.indexOf(VfModule.History)

const readResourceSpecification = mapZomeFn<ReadParams, ResourceSpecificationResponse>(dnaConfig, conductorUri, 'specification', 'resource_specification', 'get_resource_specification')
const readProcessSpecification = mapZomeFn<ReadParams, ProcessSpecificationResponse>(dnaConfig, conductorUri, 'specification', 'process_specification', 'get_process_specification')
const readAction = mapZomeFn<ById, Action>(dnaConfig, conductorUri, 'specification', 'action', 'get_action')
const readRecipeProcess = mapZomeFn<ReadParams, RecipeProcessResponse>(dnaConfig, conductorUri, 'planning', 'recipe_process', 'get_recipe_process')
const readRevision = mapZomeFn<ByRevision, RecipeFlowResponse>(dnaConfig, conductorUri, 'planning', 'recipe_flow', 'get_revision')
// const readProcessSpecification = mapZomeFn<ReadParams, ProcessSpecificationResponse>(dnaConfig, conductorUri, 'specification', 'process_specification', 'get_process_specification')
// const readAction = mapZomeFn<ById, Action>(dnaConfig, conductorUri, 'specification', 'action', 'get_action')
const readRecipeProcess = mapZomeFn<ReadParams, RecipeProcessResponse>(dnaConfig, conductorUri, 'recipe', 'recipe_process', 'get_recipe_process')
const readRevision = mapZomeFn<ByRevision, RecipeFlowResponse>(dnaConfig, conductorUri, 'recipe', 'recipe_flow', 'get_revision')

return Object.assign(
(hasResourceSpecification ? {
resourceConformsTo: async (record: { resourceConformsTo: ResourceSpecificationAddress }): Promise<ResourceSpecification> => {
return (await readResourceSpecification({ address: record.resourceConformsTo })).resourceSpecification
},
} : {}),
(hasProcessSpecification ? {
processConformsTo: async (record: { stage: ProcessSpecificationAddress }): Promise<ProcessSpecification> => {
return (await readProcessSpecification({ address: record.stage })).processSpecification
},
} : {}),
(hasAction ? {
action: async (record: { action: AddressableIdentifier }): Promise<Action> => {
return (await readAction({ id: record.action }))
},
} : {}),
(hasRecipeInput ? {
{
recipeInputOf: async (record: { recipeInputOf: RecipeProcessAddress }): Promise<RecipeProcess> => {
return (await readRecipeProcess({ address: record.recipeInputOf })).recipeProcess
},
} : {}),
(hasRecipeOutput ? {
recipeOutputOf: async (record: { recipeOutputOf: RecipeProcessAddress }): Promise<RecipeProcess> => {
return (await readRecipeProcess({ address: record.recipeOutputOf })).recipeProcess
},
},
(hasResourceSpecification ? {
resourceConformsTo: async (record: { resourceConformsTo: ResourceSpecificationAddress }): Promise<ResourceSpecification> => {
return (await readResourceSpecification({ address: record.resourceConformsTo })).resourceSpecification
},
} : {}),
// (hasAction ? {
// action: async (record: { action: AddressableIdentifier }): Promise<Action> => {
// return (await readAction({ id: record.action }))
// },
// } : {}),
(hasHistory ? {
revision: async (record: RecipeFlow, args: { revisionId: AddressableIdentifier }): Promise<RecipeFlow> => {
return (await readRevision(args)).recipeFlow
Expand Down
16 changes: 8 additions & 8 deletions modules/vf-graphql-holochain/resolvers/recipeProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {
// const extractProposedIntent = (data): ProposedIntent => data.proposedIntent

export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DNAIdMappings, conductorUri: string) => {
const hasAction = -1 !== enabledVFModules.indexOf(VfModule.Action)
// const hasAction = -1 !== enabledVFModules.indexOf(VfModule.Action)
const hasHistory = -1 !== enabledVFModules.indexOf(VfModule.History)
const hasProcessSpecification = -1 !== enabledVFModules.indexOf(VfModule.ProcessSpecification)

const readRevision = mapZomeFn<ByRevision, RecipeProcessResponse>(dnaConfig, conductorUri, 'planning', 'recipe_process', 'get_revision')
const readAction = mapZomeFn<ById, Action>(dnaConfig, conductorUri, 'specification', 'action', 'get_action')
const readRevision = mapZomeFn<ByRevision, RecipeProcessResponse>(dnaConfig, conductorUri, 'recipe', 'recipe_process', 'get_revision')
// const readAction = mapZomeFn<ById, Action>(dnaConfig, conductorUri, 'specification', 'action', 'get_action')
const readProcessSpecification = mapZomeFn<ReadParams, ProcessSpecificationResponse>(dnaConfig, conductorUri, 'specification', 'process_specification', 'get_process_specification')
// const readProcesses = mapZomeFn<ProcessSearchInput, ProcessConnection>(dnaConfig, conductorUri, 'observation', 'process_index', 'query_processes')

Expand All @@ -36,11 +36,11 @@ export default (enabledVFModules: VfModule[] = DEFAULT_VF_MODULES, dnaConfig: DN
return (await readRevision(args)).recipeProcess
},
} : {}),
(hasAction ? {
action: async (record: { action: AddressableIdentifier }): Promise<Action> => {
return (await readAction({ id: record.action }))
},
} : {}),
// (hasAction ? {
// action: async (record: { action: AddressableIdentifier }): Promise<Action> => {
// return (await readAction({ id: record.action }))
// },
// } : {}),
(hasProcessSpecification ? {
processConformsTo: async (record: { processConformsTo: ProcessSpecificationAddress }): Promise<ProcessSpecification> => {
return (await readProcessSpecification({ address: record.processConformsTo })).processSpecification
Expand Down
7 changes: 3 additions & 4 deletions modules/vf-graphql-holochain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export enum VfModule {
Commitment = 'commitment',
Satisfaction = 'satisfaction',
Proposal = 'proposal',
RecipeFlow = 'recipe',
RecipeProcess = 'recipe',
Recipe = 'recipe',
}

// default 'full suite' VF module set supported by hREA
Expand All @@ -196,8 +195,8 @@ export const DEFAULT_VF_MODULES = [
VfModule.Intent,
VfModule.Commitment,
VfModule.Satisfaction,
VfModule.RecipeFlow,
VfModule.RecipeProcess,
// Recipe DNA
VfModule.Recipe,
]

// scalar types
Expand Down

0 comments on commit 8918eac

Please sign in to comment.