-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Problem
I'm trying to use usecase2mutation with an usecase that don't needs a response, but the usecase2mutation requires it
my usecase:
const useCase = ({ profileRepository }) =>
usecase('Delete Profile', {
request: { indexer: String },
'Update the Profile': step(async ctx => {
await profileRepository.delete(ctx.req.indexer)
return Ok()
})
})when I transform it usingusecase2mutation(usecase, defaultResolver(usecase) I got this error:
> herbs-project@1.0.0 start /Users/italojs/dev/herbjs/herbs-cli/lab
> node src/index.js
/Users/italojs/dev/herbjs/herbs-cli/lab/node_modules/herbs2gql/src/usecase2type.js:14
throw error
^
InvalidUseCase: {"response":[{"cantBeEmpty":true},{"cantBeNull":true}]}
at usecase2type (/Users/italojs/dev/herbjs/herbs-cli/lab/node_modules/herbs2gql/src/usecase2type.js:10:23)
at usecase2mutation (/Users/italojs/dev/herbjs/herbs-cli/lab/node_modules/herbs2gql/src/usecase2mutation.js:4:12)
at /Users/italojs/dev/herbjs/herbs-cli/lab/src/infra/api/graphql/mutations.js:5:47
at Array.map (<anonymous>)
at Object.factory (/Users/italojs/dev/herbjs/herbs-cli/lab/src/infra/api/graphql/mutations.js:5:32)
at Object.<anonymous> (/Users/italojs/dev/herbjs/herbs-cli/lab/src/infra/api/graphql/index.js:29:75)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
invalidArgs: { response: [ { cantBeEmpty: true }, { cantBeNull: true } ] }
}
it says that my usecase needs an response type,I tried use null but I got the same error.
Solution
I believe we can create an scalar Void type by default into the default schema, so we can use it when a usecase return nothing.
Inside useCaseValidator we can remove the line 16 const responseValidation = validate(useCase.responseSchema, defaultValidator). So when we get a usecase without response type into usecaseResponse2gql we can return Void
the final result will be somethinkg like
type Mutation {
deleteProfile(indexer: string): Void
}
here we have an clear explanation about the solution https://stackoverflow.com/a/61714123
Metadata
Metadata
Assignees
Labels
Type
Projects
Status