prisma / prisma1

πŸ’Ύ Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
https://v1.prisma.io/docs/
Apache License 2.0
16.55k stars 862 forks source link

Prisma deploy doesn't generate files on windows #2494

Closed blocka closed 6 years ago

blocka commented 6 years ago

Bug Report

Current behavior prisma deploy is not generating files

Reproduction 1) install typescript-basic boilerplate 2) delete generated files 3) prisma deploy

Expected behavior? Should see generated files again

marktani commented 6 years ago

Thanks for the bug report!

It looks like the problem is that prisma-binding has been upgraded to 2.x, but graphql prepare is still used instead of graphql codegen.

We'll update this soon!

yocheved commented 6 years ago

The latest boilerplate is using graphql codegen and it's still not generating files. I have tried this with prisma-binding still on version 1.5.19 and graphql prepare and it still doesnt work. Versions: prisma/1.8.3 (windows-x64) node-v8.11.2

marktani commented 6 years ago

The problem is that .graphqlconfig.yml is not correctly configured :slightly_smiling_face:

yocheved commented 6 years ago
projects:
  app:
    schemaPath: src/schema.graphql
    extensions:
      endpoints:
        default: http://localhost:4000
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml
      prepare-binding:
        output: src/generated/prisma.ts
        generator: prisma-ts

What is incorrect in there? Is there something I can change that will make this work?

yocheved commented 6 years ago

To clarify, when I run prisma deploy it does show this outcome

post-deploy:
Running graphql get-schema --project database √
Running graphql prepare √

but no files are generated. If I run those commands each on their own in the cmd prompt, that does generate the files.

nikolasburk commented 6 years ago

Sorry for the confusion, the code generation for prisma-binding 2.0 works slightly differently as it's not using the graphql prepare but the new graphql codegen command instead.

You basically need to update your prisma.yml and the .graphqlconfig.yml:

prisma.yml

# ... other properties

hooks:
  post-deploy:
    - graphql get-schema
    - graphql codegen

.graphqlconfig.yml

projects:
  myapp:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: prisma/prisma.yml
      codegen:
        - generator: prisma-binding
          language: typescript
          output:
            binding: src/generated/prisma.ts

Let me know if you have any further questions πŸ™Œ

You can also find more info in the docs here.

yocheved commented 6 years ago

@nikolasburk I'm using prisma-binding version 1.5.19 with graphql prepare in one project and prisma-binding version 2.0.1 with graphql codegen in another place and am getting the same results for both projects. The hooks run after prisma deploy but do not generate any files or changes unless I run them manually. I believe this is a windows issue because other people using linux have told me that this works for them.

nikolasburk commented 6 years ago

Hmm, I see. In that case I'm reopening the issue for someone to look into that specific case. Thanks @yocheved πŸ™

marktani commented 6 years ago

@yocheved can you provide reproduction repositories for both cases? :slightly_smiling_face:

blocka commented 6 years ago

I was able to reproduce this directly from the typescript-basic boilerplate.

marktani commented 6 years ago

Yes @blocka, I also was able to reproduce, but we adjusted the typescript-basic boilerplate since you reported the error :slightly_smiling_face: Can you still reproduce the issue?

blocka commented 6 years ago

Sorry for the delay, It is still an issue.

gsancho commented 6 years ago

i have the same problem :(

PhilipBridges commented 6 years ago

I believe prisma deploy is not running graphql get-schema --project database properly. Or maybe it's not passing the users .env flags. But regardless, if I run prisma deploy then manually run graphql get-schema --project database --dotenv=myenvpath, it generates the file properly. So is this just a script error?

ntziolis commented 6 years ago

@marktani This problem still persists after latest upgrades to boilerplate projects:

Getting the following warnings warning command prepare both exists in plugin C:\project\node_modules\graphql-cli-prepare and is shipped with the graphql-cli.

Basically that leaves us not being able to migrate to 1.7+ right now.

.graphqlconfig:

projects:
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml
      codegen:
        - generator: prisma-binding
          language: typescript
          output:
            binding: src/generated/prisma.ts

prisma.yml


# the full uri to the prisma endpoint
endpoint: ${env:PRISMA_ENDPOINT}

# the file path pointing to your data model
datamodel: datamodel.graphql

# to disable authentication uncomment below
secret: ${env:PRISMA_SECRET}

# seed your service with initial data
seed:
  import: ${env:PRISMA_SEED}

# Download the GraphQL schema of the Prisma API into
# `src/generated/prisma.graphql` (as specfied in `.graphqlconfig.yml`).
# Then generate the corresponding TypeScript definitions into
# `src/generated/prisma.ts` (also specfied in `.graphqlconfig.yml`)
# with `graphql codegen` .
hooks:
  post-deploy:
    - graphql get-schema --project database
    - graphql codegen --project database

folder structure: database/prisma.yml database/datamodel.graphql .graphqlconfig

marktani commented 6 years ago

Thanks for your feedback @ntziolis! Can you share your .graphqlconfig.yml and the hooks from prisma.yml?

ntziolis commented 6 years ago

@marktani Was in the rpocess of updating my post

marktani commented 6 years ago

Does it work if you run graphql codegen directly from the command line, and not as a hook?

ntziolis commented 6 years ago

Nope, same result reports success + warning. Even tried with specific project but same result: image

ntziolis commented 6 years ago

The issue was as suggested graphql-cli-prepare, once i manually deleted the node module folder for this package creation of bindings ran smoothly ... sadly now other pieces break where graphql cli prepare was being used.

I will provide an update once I figure out how to remove the dep to graphql-cli-prepare

ntziolis commented 6 years ago

Basically im out of ideas. My initial report that I was able to create the file after removing the prepare lib was FALSE. All it did was remove the error message. still no prisma.ts though.

Here is is a step by step to understand what changes when:

ntziolis commented 6 years ago

I have taken some time to summarize this issue as I think this are multiple:

  1. (solved) New way the code generation gets triggered
  2. (solved) Codegen has to be used instead of prepare, which was wrong in the old boilerplates
  3. (open) prisma deploy does not properly trigger running scripts (at least on windows)
  4. (open) While graphql get-schema' works when manually executedgraphql codegen `command does NOT work on windows when manually executed

Summary I think we can live with no 3 for a bit, but NOT with No 4 as this basically requires windows folks to stay below version 1.7.

marktani commented 6 years ago

Thanks for the summary, @ntziolis. We will work on this issue soon! :slightly_smiling_face:


One note, graphql codegen is tied to prisma-binding version 2.x, while graphql prepare is tied to prisma-binding version 1.5.x.

Neither is tied to the prisma version itself, so if you want to upgrade to prisma 1.7+, you can do so on Windows as well, if you use prisma-binding version 1.5.x and graphql prepare :slightly_smiling_face:

ntziolis commented 6 years ago

Thank you for the workaround.

divyenduz commented 6 years ago

I am able to replicate this issue (prisma-binding 2.0 with graphql codegen) on windows, and on mac machines when I remove the node_modules folder.

I have created an issue with related findings.

yocheved commented 6 years ago

@divyenduz, I am using prisma-binding version 1.5.19 and prisma version 1.8.3 on Windows. When I run prisma deploy, it does run the hooks and gives this output

post-deploy:
Running graphql get-schema --project database √
Running graphql prepare √

but the files dont change. When I run each of those hooks manually, they give different output:

graphql get-schema --project database
warning command prepare both exists in plugin E:\GitHub\team-fundraising\node_modules\graphql-cli-prepare and is shipped with the graphql-cli.
The plugin is being ignored.
project database - No changes

AND

graphql prepare
warning command prepare both exists in plugin E:\GitHub\team-fundraising\node_modules\graphql-cli-prepare and is shipped with the graphql-cli.
The plugin is being ignored.
√ Bindings for project database written to src/generated/prisma.ts

and files do get generated

williamluke4 commented 6 years ago

Same issue here

zjyonline commented 6 years ago

Prisma deploy doesn't generate files on mac. My graphqlconfig.yml content is

prisma:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: prisma/prisma.yml

prisma.yml is

hooks:
  post-deploy:
    - graphql get-schema --project prisma

and I run deploy command, there is no file named 'prisma.graphql' created.

jhalborg commented 6 years ago

@marktani - Can you explain that workaround from your previous comment for people who've just started with the advanced boilerplate and prisma 1.8 and prisma-binding 2.x.x ? What should the post-deploy hook look like, and what packages and versions should be used while we wait for a fix here?

williamluke4 commented 6 years ago

@jhalborg Your link takes you too av-cables.dk!

jhalborg commented 6 years ago

@williamluke4 - Sorry, my bad πŸ˜† Fixed

zjyonline commented 6 years ago

I solve my problem with command npm install -g graphql-cli then I deploy my project,show that: project prisma - Schema file was created: src/generated/prisma.graphql

yocheved commented 6 years ago

@zjyonline that didn't fix it for me

ntziolis commented 6 years ago

@zjyonline didn't fix it for me either.

zjyonline commented 6 years ago

I found that hooks command run in this file in my Mac , /usr/local/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/commands/deploy/index.js about lin4 400,

          case 11:
                    hooks = this.definition.getHooks('post-deploy');
                    if (hooks.length > 0) {
                        this.out.log("\n" + chalk_1.default.bold('post-deploy') + ":");
                    }
                    for (_i = 0, hooks_1 = hooks; _i < hooks_1.length; _i++) {
                        hook = hooks_1[_i];
                        splittedHook = hook.split(' ');
                        this.out.action.start("Running " + chalk_1.default.cyan(hook));
                        child = **npm_run_1.spawnSync(splittedHook[0], splittedHook.slice(1));**
                        stderr = child.stderr && child.stderr.toString();
                        if (stderr && stderr.length > 0) {
                            this.out.log(stderr);
                        }
                        stdout = child.stdout && child.stdout.toString();
                        if (stdout) {
                            this.out.log(stdout);
                        }
                        this.out.action.stop();
                    }
                    return [2 /*return*/];

So I found maybe I forget to install something about 'graphql-cli' ? @yocheved @ntziolis read this file maybe help.

jhalborg commented 6 years ago

Any ETA on this? It's blocking half our development team πŸ˜„

ntziolis commented 6 years ago

Im near death certain it’s related to some versions of node spawning not working properly on Windows or only with different params. I ran into an issue like that some time ago. I’ll check and report back thx for pointing to the right place.

divyenduz commented 6 years ago

@ntziolis : Hello, you are kinda correct, we are working on a solution and we should be able to release it soon.

@jhalborg: soon, hopefully in a few hours!

divyenduz commented 6 years ago

This is released in graphql-cli version 2.6.1.

Please update the graphql-cli and try out the graphql codegen command.

This is how the graphql config should look like

ntziolis commented 6 years ago

Wow 20min to close it. Will test as soon as in front of pc!

williamluke4 commented 6 years ago

Just tested with "prisma-binding": "^2.0.2" and "graphql-cli": "^2.16.1" and is working! Thanks guys

ntziolis commented 6 years ago

I can confirm that graphql codegen now works with graphql-cli@2.6.1 + prisma-bindings@2.0.2. One issue closed, one left to go.

Updating the summary I made previously:

Assuming the first error was in the way graphql codegen spawns apollo-codegen. It should basically be the same fix for prisma deploy which spawns graphql get-schema + graphql codegen.

divyenduz commented 6 years ago

@ntziolis : Can you please share your graphql config and prisma.yml file and prisma cli version via prisma --version?

The latest prisma cli requires hooks to be defined in prisma.yml to add graphql get-schema and graphql codegen post deploy.

P.S. I observed that you have shared the relevant files already, trying to replicate on windows.

ntziolis commented 6 years ago

@divyenduz I understand the changes and have implemented them @marktani has already double checked them above.

My prisma version is: prisma/1.8.3 (windows-x64) node-v8.9.4

To be clear:

Here is what my console looks like:

# prisma deploy
Deploying service `circula` to stage `dev` to server `local` 167ms
Service is already up to date.

post-deploy:
Running graphql get-schema --project database √
Running graphql codegen --project database √

=> No files get created, neither prisma.ts nor schema.graphql

Updated Notes:

divyenduz commented 6 years ago

πŸŽ‰This is released in prisma cli version 1.9. πŸŽ‰

Please download using npm install -g prisma

ntziolis commented 6 years ago

@divyenduz Right now this does not work, when installing prisma it only installs 1.8.3. npm side says this is the most recent version. did something go wrong during publishing to npm?

marktani commented 6 years ago

Yes, we're looking into publishing 1.9 to npm tomorrow.

abelovic commented 6 years ago

When you create a release it should be published to npm at the same time as part of your deployment process always

marktani commented 6 years ago

Yes, we're setting up an automatic publishing flow as you suggested :slightly_smiling_face:

rohmanhm commented 6 years ago

I still get the error message, but everything worked well.

I'm on Windows 10

Here the error message

Romsy@ROMSY-PC MINGW64
$ prisma deploy
Deploying service `default` to stage `default` to server `default` 48ms
Service is already up to date.

post-deploy:
warning command prepare both exists in plugin pathsomewhere\node_modules\graphql-cli-prepare and is shipped with the graphql-cli.
The plugin is being ignored.

Running graphql get-schema --project database...
project database - No changes
Running graphql get-schema --project database √
warning command prepare both exists in plugin pathsomewhere\node_modules\graphql-cli-prepare and is shipped with the graphql-cli.
The plugin is being ignored.

Running graphql codegen √

Here's my dep and devDep

  "dependencies": {
    "bcryptjs": "2.4.3",
    "graphql-yoga": "1.14.10",
    "jsonwebtoken": "8.3.0",
    "prisma-binding": "2.1.0"
  },
  "devDependencies": {
    "@types/bcryptjs": "2.4.1",
    "dotenv-cli": "1.4.0",
    "graphql-cli": "2.16.3",
    "nodemon": "1.17.5",
    "npm-run-all": "4.1.3",
    "prisma": "1.10.2",
    "rimraf": "2.6.2",
    "ts-node": "6.2.0",
    "typescript": "2.9.2"
  }