diff --git a/src/helpers/gqlConverters.js b/src/helpers/gqlConverters.js index 69ef905..e8dfbaf 100644 --- a/src/helpers/gqlConverters.js +++ b/src/helpers/gqlConverters.js @@ -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 } diff --git a/src/herbarium2gql.js b/src/herbarium2gql.js index 1482b9f..c53b301 100644 --- a/src/herbarium2gql.js +++ b/src/herbarium2gql.js @@ -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))] diff --git a/test/support/herbarium/genericHerbariumObject.js b/test/support/herbarium/genericHerbariumObject.js index 5b046c5..75a7fff 100644 --- a/test/support/herbarium/genericHerbariumObject.js +++ b/test/support/herbarium/genericHerbariumObject.js @@ -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 }