MichalLytek / MichalLytek/type-graphql
Feature Request: Library to Generate Client
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
Trying to write client code which queries a graphql server whose resolvers and types were defined using type-graphql.
I'm building a webpack-dev-server alternative that supports HMR in node and web and I'd like to use graphql to define a data-transfer method agnostic API for fetching bundle updates & eventually support remote javascript debugging
Describe the solution you'd like
I would like a typescript graphql client to be generated at compile-time based on the type-graphql @ObjectType definitions, with a design-time, typed client API available. This could be a separate package from type-graphql, like type-graphql-client.
Describe alternatives you've considered
- https://github.com/helios1138/graphql-typed-client
- https://github.com/mobxjs/mst-gql
- https://github.com/samdenty/gqless
The third option doesn't work because it's React specific. The first two are headed in the right direction, but they vend a CLI that requires connection to a running graphql server. These options just inspect the predefined schema in order to generate the client, so theoretically we should be able to generate a client based on type-graphql @ObjectTypes, since these @ObjectTypes act as the source of truth for generating a graphql schema.
Additional context
Ideally, the type-graphql annotated @ObjectType classes would be isomorphic typescript, a DTO shared between client and server. Often times clients are bundled (via webpack for example), but right now there are difficulties bundling type-graphql into a webpack bundle because it has node-specific dependencies (there are imports to fs and path in the codebase for example) which means I can't bring an @ObjectType annotated class into a web targeted bundle without some config hacks. One workaround would be to separate the type-graphql annotations into a separate library like type-graphql-annotations which has zero dependencies and is written to run in any javascript runtime; in this case the annotations would be used more like meta-data tags rather than performing any operations, and then the main type-graphql node library or the type-graphql-client library would be able to interpret the meaning of the tags then generate a graphql schema via graphql-js or a graphql client respectively.
Ideally the type-graphql-client library would only know how to generate query strings, and would have no knowledge of where or how to submit the strings. That choice would be left up to clients of the library.
If you're open to something like this, I'd be happy organize this project (understand type-graphql more, organize a backlog, work on some epics/stories/tasks).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed type-graphql-client package, the @ObjectType annotations, and the referenced src/browser-shim.ts. Clarify whether generation should produce only query strings and whether annotations must be split into a runtime-neutral package; a completed issue would have an agreed design and backlog before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100