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

Created on 2 Apr 2019  路  5Comments  路  Source: nestjs/graphql

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

done

All 5 comments

Thanks for reporting!

It should be available in the @next version ($ npm i @nestjs/graphql@next). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/[email protected]). Simply set autoSchemaFile: true instead of passing a filename.

Please, let me know if you face any issue.

Published as 6.2.0 ($ npm i @nestjs/graphql@latest). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/core@latest)

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. (C:\work\UI\NEST\auth-appnode_modules\type-graphql\dist\schema\schema-generator.js:20:27)

@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!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings