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

Type GraphQL doesn't allow converting a class to a schema #1061

Closed
adam-arold opened this issue Oct 5, 2021 · 3 comments
Closed

Type GraphQL doesn't allow converting a class to a schema #1061

adam-arold opened this issue Oct 5, 2021 · 3 comments
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists

Comments

@adam-arold
Copy link

Type GraphQL exposes the buildSchema function but only works with resolvers. It must have some internal function that converts the class into a schema but it is not exposed at all, so I cannot opt-out of having a resolver. My use case is that I want to have a transportable schema (class -> string) that I can reuse elsewhere, but I don't want the resolver.

In theory this should be working without adding extra functionality, but it is not exposed, at least I didn't find it. (It would also be useful if Type GraphQL had reference documentation.

I tried creating a JSON Schema from my class and coverting it to a GraphQL schema. This worked for simple cases, but I didn't find a tool that supports $refs, and I have them in my code.

The project I'm working on consists of an SDK where you can register your schemas, and send your data based on this schema, and a server component that aggregates data from multiple services. For this reason, I need programmatic control over what is created and how, and I can't have resolvers in the SDK (I will have a central resolver on the backend instead).

@MichalLytek
Copy link
Owner

I'm afraid I'm not able to help you.

Classes are only a carrier for the decorators, which registers the metadata (type, fields, names) and then acts as a token to get the metadata back from the storage when buildSchema is called, in order to create GraphQLSchema programmatically like with a raw graphql-js.

So your use case basically means you would need to serialize the metadata storage and then magically serialize class methods as they are the graphql resolvers functions.

@MichalLytek MichalLytek added Out of scope ✖️ Proposal doesn't fit in project goals Question ❔ Not future request, proposal or bug issue labels Oct 5, 2021
@adam-arold
Copy link
Author

I only use plain classes (DTOs) without functionality.

@MichalLytek
Copy link
Owner

So it's a duplicate of #339 🔒

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists and removed Question ❔ Not future request, proposal or bug issue Out of scope ✖️ Proposal doesn't fit in project goals labels Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants