Skip to content

Commit

Permalink
feat(herbarium): run on the new Herbarium Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dalssoft committed Aug 8, 2023
1 parent 14e0b11 commit a1b38e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/helpers/gqlConverters.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function entityFieldType2gql(type, param) {
if (hasIDs(type)) name = `${typeNames}IDsInput`
else name = `${typeNames}Input`
}
else name = type.name
else name = upperFirst(camelCase(type.name))
return name
}

Expand Down
16 changes: 10 additions & 6 deletions src/herbarium2gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const { entity, field } = require('@herbsjs/herbs')


function herbs2gql({herbarium, resolver = defaultResolver}) {
const { usecases, entities, crud } = herbarium
const usecases = herbarium.nodes.find({ type: herbarium.node.usecase })
const entities = herbarium.nodes.find({ type: herbarium.node.entity })
const crud = herbarium.crud

const entitiesName = Array.from(entities.all.values()).map((e) => e.entity)
const entitiesName = entities.map((e) => e.value)
const queryUseCases = usecases
.findBy({ operation: [crud.read, crud.readAll] })
.map((e) => e.usecase)
// find all usecases that are read or readAll
.filter((uc) => [crud.read, crud.readAll].includes(uc?.metadatas?.operation))
.map((e) => e.value)
const mutatitonUseCases = usecases
.findBy({ operation: [crud.create, crud.update, crud.delete] })
.map((e) => e.usecase)
// .findBy({ operation: [crud.create, crud.update, crud.delete] })
.filter((uc) => [crud.create, crud.update, crud.delete].includes(uc?.metadatas?.operation))
.map((e) => e.value)

const inputs = mutatitonUseCases.map((usecase) =>
[usecase2input(usecase(), resolver(usecase))]
Expand Down
36 changes: 14 additions & 22 deletions test/support/herbarium/genericHerbariumObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,19 @@ const givenAnUseCaseThatResturnsDate = (injection) =>
response: Date,
})

herbarium.entities.add(SimpleEntity, 'SimpleEntity')
herbarium.entities.add(NoIDEntity, 'NoIDEntity')
herbarium.entities.add(CoolEntity, 'CoolEntity')
herbarium.usecases.add(givenACreateUseCase, 'CreateSomethingCool').metadata({
group: 'genericGroup',
operation: herbarium.crud.create,
entity: CoolEntity,
})
herbarium.usecases.add(givenAUpdateUseCase, 'UpdateSomethingCool').metadata({
group: 'genericGroup',
operation: herbarium.crud.update,
entity: CoolEntity,
})
herbarium.usecases.add(givenAGetUseCase, 'GetSomethingCool').metadata({
group: 'genericGroup',
operation: herbarium.crud.read,
entity: CoolEntity,
})
herbarium.usecases.add(givenAnUseCaseThatResturnsDate, 'givenAnUseCaseThatResturnsDate').metadata({
group: 'genericGroup',
operation: herbarium.crud.read,
})
herbarium.nodes.add('SimpleEntity', SimpleEntity, herbarium.node.entity)
herbarium.nodes.add('NoIDEntity', NoIDEntity, herbarium.node.entity)
herbarium.nodes.add('CoolEntity', CoolEntity, herbarium.node.entity)
herbarium.nodes.add('CreateSomethingCool', givenACreateUseCase, herbarium.node.usecase)
.metadata({ operation: herbarium.crud.create })
.link('CoolEntity')
herbarium.nodes.add('UpdateSomethingCool', givenAUpdateUseCase, herbarium.node.usecase)
.metadata({ operation: herbarium.crud.update })
.link('CoolEntity')
herbarium.nodes.add('GetSomethingCool', givenAGetUseCase, herbarium.node.usecase)
.metadata({ operation: herbarium.crud.read })
.link('CoolEntity')
herbarium.nodes.add('givenAnUseCaseThatResturnsDate', givenAnUseCaseThatResturnsDate, herbarium.node.usecase)
.metadata({ operation: herbarium.crud.read })

module.exports = { herbarium }

0 comments on commit a1b38e4

Please sign in to comment.