Blitz: Generator is writing incorrect paths for queries and mutations

Created on 2 May 2020  路  9Comments  路  Source: blitz-js/blitz

What is the problem?

blitz generate is creating queries and mutations one level too deep (under an additional model directory).

Example:

Received: app\projects\queries\projects\getProjects.ts
Expected: app\projects\queries\getProjects.ts

Steps to Reproduce:

  1. blitz new myapp
  2. cd myapp
  3. blitz generate all project

Versions:

debug: monorepo
debug: pkgPath: C:\dev\contrib\blitz\node_modules\@blitzjs\cli

Windows 10 | win32-x64 | Node: v12.16.1

blitz: 0.8.1 (global)
blitz: 0.8.1 (local)

Supporting Documentation

CREATE    app\projects\pages\projects\index.tsx
CREATE    app\projects\pages\projects\new.tsx
CREATE    app\projects\pages\projects\[id]\edit.tsx
CREATE    app\projects\pages\projects\[id].tsx
CREATE    app\projects\queries\projects\getProjects.ts
CREATE    app\projects\queries\projects\getProject.ts
CREATE    app\projects\mutations\projects\createProject.ts
CREATE    app\projects\mutations\projects\deleteProject.ts
CREATE    app\projects\mutations\projects\updateProject.ts
kinbug priorithigh scopcli statudone

Most helpful comment

@johncantrell97 thanks for the report. I've been away from the computer for much of the weekend, but I'll take a look at this this afternoon. Sorry for the inconvenience here 馃槥

All 9 comments

Yeah this was known, good thought that it's a weird first experience though.

My general thoughts here are that we currently try to make a lot of assumptions in cli/generate about file paths, but in reality that's hard because a couple generators (app, pages) have special rules that don't apply to the rest of the generators. I think I'd like to push that logic out into the generators and let the generator declare its own path via a set of heuristics rather than the one-size-fits-all approach that we currently have.

As a first pass I'll probably just hard-code some logic in the generator that special-cases PageGenerator and revisit the cleanup next week

Yeah, I told a friend to check out Blitz and his immediate response was, "Sounds cool, but the tutorial doesn't even work." Oops. 馃槵

Generators declaring their own paths down the road with a temporary, hard-coded special case sounds reasonable. 馃憤

Thanks!

馃憤 Just ran into this as well when going through the tutorial to try creating a sample app to play with

@johncantrell97 thanks for the report. I've been away from the computer for much of the weekend, but I'll take a look at this this afternoon. Sorry for the inconvenience here 馃槥

@aem this used to work 鈥斅燿o we know what caused it to break?

And how soon can we get a hot fix published?

@flybayer i鈥檓 not totally sure, i鈥檝e got something mostly working locally though, should be able to put up a PR in a few minutes

i think the issue is with generator templates.

Previous Version:
import get__ModelNames__ from 'app/__modelNames__/queries/get__ModelNames__'

Modified Version:
import get__ModelNames__ from 'app/__modelNames__/queries/__modelNames__/get__ModelNames__'

@ganeshmani the import paths are correct, it's the path of the generated files that is wrong.

Broken: app\projects\queries\projects\getProjects.ts
Correct: app\projects\queries\getProjects.ts

Fixed in blitz 0.8.2!

Was this page helpful?
0 / 5 - 0 ratings