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

Possibility to emit schema file in offline context #11

Open
JohannesKlauss opened this issue Oct 20, 2020 · 5 comments
Open

Possibility to emit schema file in offline context #11

JohannesKlauss opened this issue Oct 20, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@JohannesKlauss
Copy link

Currently, the plugin only emits a schema file on runtime, but this is not ideal for designing a microservice architecture, when other services depend on that schema file for generating their own code.

Is there a possibility to emit the schema file without having to run the NestJS server?

@MichalLytek
Copy link
Owner

NestJS has some mechanism to do that:
https://docs.nestjs.com/graphql/generating-sdl

However, it doesn't use modules but explicit resolvers class array, which is an awful idea.

You can do the same thing just by using buildSchema imported from type-graphql.
You can put emitSchemaFile option or use emitSchemaDefinitionFile function explicitly.

I will leave that issue open to create TypeGraphQLSchemaBuilderModule which gonna accepts modules and which gonna have method for emitting SDL instead of importing printSchema requirement.

@MichalLytek MichalLytek added the enhancement New feature or request label Oct 20, 2020
@Borales
Copy link

Borales commented Jan 6, 2022

@MichalLytek hi, any update on this?

@Borales
Copy link

Borales commented Jan 7, 2022

@MichalLytek It is kind of a blocker for me, as I have a nestjs-powered backend (and I'm using code-first approach) for my graphql schema. And my client app uses graphql-codegen to generate graphql queries - but it needs a schema file to do that. On CI/CD - I want to be able to generate my schema file so that codegen would be able to generate the queries (as I can't start the app on a CI service).

The suggested solution with buildSchema - doesn't work properly, as it's missing the whole NestJS infra. I specified the resolvers glob pattern - it then started complaining it wasn't able to import other classes.

Or the emitted schema file is supposed to be git-tracked?

@Borales
Copy link

Borales commented Jan 7, 2022

@MichalLytek I'm using typegraphql-prisma and typegraphql-nestjs. So all my types are generated from Prisma schema. And I tried following buildSchema suggestion (to compile the schema via resolvers):

import 'reflect-metadata';
import { buildSchemaSync } from 'type-graphql';

const schema = buildSchemaSync({
  resolvers: [__dirname + '/../src/graphql/**/*.resolvers.ts'],
  authChecker: () => true
});

It kinda works, but it exports all Prisma definitions (which I don't need). Emitting the file during runtime (with TypeGraphQLModule) - creates a proper schema file for the types with the declared resolvers (intended behavior).

Any other suggestions?

@MichalLytek
Copy link
Owner

@Borales you need to provide the imported resolvers explicitly in order to not emit all prisma definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants