Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

required usecase-response into usecase2mutation #24

Open
italojs opened this issue Jun 1, 2021 · 3 comments
Open

required usecase-response into usecase2mutation #24

italojs opened this issue Jun 1, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed severity-minor Item is not urgent wip Work in progress

Comments

@italojs
Copy link
Member

italojs commented Jun 1, 2021

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

@italojs italojs added the enhancement New feature or request label Jun 1, 2021
@italojs italojs changed the title required response into usecase required usecase-response into usecase2mutation Jun 1, 2021
@jhomarolo jhomarolo added help wanted Extra attention is needed severity-minor Item is not urgent labels Dec 24, 2021
@italojs italojs added the ready-to-work Item is ready to work on it label May 4, 2022
@sanderiw
Copy link

sanderiw commented Jun 9, 2022

I can work on this issue!!! Jose Eduardo will help me on this PR. :-)

@jhomarolo jhomarolo added wip Work in progress and removed ready-to-work Item is ready to work on it labels Jun 10, 2022
@sanderiw
Copy link

sanderiw commented Jun 15, 2022

We've been working on this issue, but we noticed it is a little more complicated than what is described here… Now we`re gonna work on more unit testing. Maybe this PR should be worth some extra points 😃😃😃

@italojs
Copy link
Member Author

italojs commented Sep 4, 2022

@sanderiw are you still working on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed severity-minor Item is not urgent wip Work in progress
Projects
Status: In Progress
Development

No branches or pull requests

3 participants