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

Fix NamesCell reload after deleting item #519

Merged
merged 1 commit into from
May 8, 2020

Conversation

cephalization
Copy link
Contributor

Use pluralCamelName in place of hardcoded string when performing refetchQuery in delete handler

Fixes #518

Use pluralCamelName in place of hardcoded string when performing refetchQuery in delete handler
@cannikin
Copy link
Member

cannikin commented May 7, 2020

Great catch, thanks! I’ll merge as soon as it’s not in Draft! Might be a couple of test fixtures that need updates?

@cephalization
Copy link
Contributor Author

For sure! The draft is a bookmark for me to double check that it works and come back here :)

@cephalization
Copy link
Contributor Author

cephalization commented May 7, 2020

I'm thinking the test fixtures should work out of the box since they expect 'POSTS' to be generated anyway. I'm having trouble testing that the scaffolding works myself however.

I've followed the contribution guide as well as the redwood/packages/cli README but yarn rw g scaffold <model> seems to use the redwood app's cli rather than my development one example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/commands/generate/scaffold/scaffold.js.

Additionally, I get the following error when running the scaffold command on a fresh project who has had a model generated and saved with the appropriate db commands (save, up).

yarn rw g scaffold user       
yarn run v1.22.4
$ /home/tony/repos/example-redwood-sandbox/node_modules/.bin/rw g scaffold user
/home/tony/repos/example-redwood-sandbox/node_modules/yargs/yargs.js:1242
      else throw err
           ^

Error: Cannot find module 'humanize-string'
Require stack:
- /home/tony/repos/example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/commands/generate/scaffold/scaffold.js
- /home/tony/repos/example-redwood-sandbox/node_modules/yargs/index.js
- /home/tony/repos/example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/home/tony/repos/example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/commands/generate/scaffold/scaffold.js:39:46)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/tony/repos/example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/commands/generate/scaffold/scaffold.js',
    '/home/tony/repos/example-redwood-sandbox/node_modules/yargs/index.js',
    '/home/tony/repos/example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/index.js'
  ]
}
error Command failed with exit code 1.

@cephalization cephalization marked this pull request as ready for review May 7, 2020 13:58
@thedavidprice
Copy link
Contributor

I'm thinking the test fixtures should work out of the box since they expect 'POSTS' to be generated anyway. I'm having trouble testing that the scaffolding works myself however.

^^ If you're referring to Jest and ESLint tests, your 100% correct. However, although we've done a ton of work to date, the yarn rw test command (using Jest) is not yet fully working. (It's in progress now.) Once it's ready, we'll be revisiting all generator template code including tests to make sure they pass Jest and ESLint out of the box.

I've followed the contribution guide as well as the redwood/packages/cli README but yarn rw g scaffold seems to use the redwood app's cli rather than my development one example-redwood-sandbox/node_modules/@redwoodjs/cli/dist/commands/generate/scaffold/scaffold.js.

CLI development is a tricky, messy beast. You'll have to use the "Local Package Emulation" process. And each time you make changes to the package, you need to re-run the process:
https://redwoodjs.com/guides/contributing#local-package-registry-emulation

Additionally, I get the following error when running the scaffold command on a fresh project who has had a model generated and saved with the appropriate db commands (save, up).

^^ are you running this attempting to use lastest 'master' branch packages? If so, again you'll need to use the "Local Package Emulation" process. The reason is due to how newly added npm packages added to the RW Framework are not locally included automatically when trying to use the local RW Framework packages in a local RW App. That's the likely cause for this error `Error: Cannot find module 'humanize-string'

@cephalization
Copy link
Contributor Author

Following the local package reg instructions I've been able to test and confirm that my fix works :)

Fix reproduction steps:

  • Create prisma model called something other than post e.g. user

  • Save and migrate db

  • Run yarn rw g scaffold user

  • Create new user using scaffold UI

  • Delete that user using scaffold UI

  • After confirmation, the USERS query should refetch and no users should remain

@cannikin
Copy link
Member

cannikin commented May 8, 2020

AWESOME! Good to merge?

@cephalization
Copy link
Contributor Author

GTG!

@cannikin cannikin merged commit add95ad into redwoodjs:master May 8, 2020
@cannikin
Copy link
Member

cannikin commented May 8, 2020

Thanks!

@thedavidprice thedavidprice added this to the next release milestone May 8, 2020
jmreidy pushed a commit to jmreidy/redwood that referenced this pull request May 19, 2020
Use pluralCamelName in place of hardcoded string when performing refetchQuery in delete handler
jmreidy pushed a commit to jmreidy/redwood that referenced this pull request May 30, 2020
Use pluralCamelName in place of hardcoded string when performing refetchQuery in delete handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardcoded query name is refetched after deleting item in scaffolding table
3 participants