question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please give us (or document) the option to use Code First approach without saving the generated schema into a file.

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When we’re using code first approach we need to autoSchemaFile option, otherwise we get an exception

UnhandledPromiseRejectionWarning: Error: Apollo Server requires either an existing schema, modules or typeDefs

Expected behavior

When we use the code first approach we can simply use some flag to specify that’s what we’re doing now without saving the schema.gql file to the file system.

Minimal reproduction of the problem with instructions

Try using code first approach without specifying autoSchemaFile option.

What is the motivation / use case for changing the behavior?

Sometimes deployment environments are immutable, and we don’t have any need for the generated schema.gql file. The Apollo Server instance already knows everything and we can use the client for introspection without needing the file which only serves as documentation in this case and we might not need it in the code and/or we can’t actually save it depending on the environment (would need to use tmp dir or something like that).

Environment


Nest version: 6.0.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nicky-lenaerscommented, Jun 7, 2019

@venkatamandala I had this issue too. Solved it as follows:

  1. I needed to setup .graphql (so Schema First approach) once in order for the schema.gql to be generated. So I made a very simple temp.graphql file and updated the module config like so:
GraphQLModule.forRoot({
  ...
  typePaths: ['./**/*.graphql'], // <-- add this
  autoSchemaFile: 'schema.gql'
})
  1. I restarted the NestJS server and this time it did generate the schema.gql file. Then I changed it back to the config without the typePaths option, like so:
GraphQLModule.forRoot({
  ... // no more typePaths
  autoSchemaFile: 'schema.gql'
})
  1. Now the schema.gql get updated using the Code First approach. My guess is that the schema.gql file simply needed to exist, but I’m unsure about that.

Hope it helps!

1reaction
venkatamandalacommented, May 21, 2019

Followed as you mentioend above, but still having issues

//Package json “@nestjs/common”: “^6.0.0”, “@nestjs/core”: “^6.2.3”, “@nestjs/graphql”: “^6.2.1”,

//app.module.ts GraphQLModule.forRoot({autoSchemaFile: true, debug: false, playground: false, context: ({ req }) => ({ req })}),

//Error node:35352) UnhandledPromiseRejectionWarning: Error: Generating schema error [0] at Function.<anonymous> (C:\work\UI\NEST\auth-app\node_modules\type-graphql\dist\schema\schema-generator.js:20:27)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code First Migrations in Team Environments - EF6
Automatic migrations allows you to have your database schema updated to match the current model without the need to generate code files ......
Read more >
Migrations and Seed Data With Entity Framework Core
We are going to learn about Migrations and Seed data in Entity Framework Core and how to optimize EF Core migrations.
Read more >
Create Entity Data Model - Entity Framework Tutorial
Here, we are going to create an Entity Data Model (EDM) for an existing database in database-first approach and understand the basic building...
Read more >
Specifying a schema | BigQuery - Google Cloud
When you use a JSON array, you generate the schema using the same process as creating a JSON schema file. Click Create table....
Read more >
CSV Files - Spark 3.3.1 Documentation
Property Name Default Scope sep, read/write encoding UTF‑8 read/write quote " read/write
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found