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

Generate schema.graphql without running the server #291

Closed
matthieudesprez opened this issue Jun 13, 2019 · 6 comments
Closed

Generate schema.graphql without running the server #291

matthieudesprez opened this issue Jun 13, 2019 · 6 comments

Comments

@matthieudesprez
Copy link

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

schema.graphql is only generated when the serving is running

Expected behavior

it would be nice to have a way for generating the schema.graphql from command line

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

the current behavior causes troubles when merging branches which contain resolver modifications, we have to run the server to update the schema.graphql

@marcus-sa
Copy link
Contributor

Take a look at https://graphql-code-generator.com :)

@matthieudesprez
Copy link
Author

matthieudesprez commented Jun 13, 2019

Thanks but graphql-code-generator generates code from graphql and I need the other way around.

Currently, my nest module looks like this:

@Module({
  imports: [
    GraphQLModule.forRoot({
      autoSchemaFile: join(process.cwd(), 'apps/api/src/graphql/schema.graphql'),
      installSubscriptionHandlers: true,
      tracing: true,
      debug: true
    }),
    ...other modules
  ]
})

With this, nestjs/graphql manages to pass all imported modules, containing their own resolvers, to type-graphql for generating a schema.graphql from the code, and that's what I would like to achieve through cli without having to run the entire application

@marcus-sa
Copy link
Contributor

@matthieudesprez I think it would've been a good idea to mention that you're using type-graphql in the initial issue description.

@arekbal
Copy link

arekbal commented Jun 14, 2019

There is no need to de facto 'run' the server to generate schema file.
You only have to create an app and do .init() on it.

If you structurize your app properly - as in making separation between bootstrapping from starting the server then there is no issue.
In full scale app, one might need it (the clean separation) for e2e tests or 'dry' run anyway.

My guide: create a scripts folder next to src, put a script there, that would call init() from src/init.ts, and add this script invocation to package.json scripts.

There are also other approaches that might work like using DynamicModule for that.

@matthieudesprez
Copy link
Author

@marcus-sa nest/graphql uses type-graphql to generate the schema.graphql

@arekbal thanks for your advice, the init() will do the trick

@lock
Copy link

lock bot commented Apr 25, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants