-
Notifications
You must be signed in to change notification settings - Fork 58
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
Multiple files support #71
Comments
Wondering if any work has been undertaken on this? Would potentially be be happy to spend sopme time on it. |
This is extremely important because it currently limits the use of ts-to-zod to only the simplest files. There's no way for users to produce a single file containing all the types you'd want to pass to |
Are there any updates on multifile support? I may be capable to develop this feature, but would like to discuss it first. |
I started something on my last plane trip but needed more time to make something usable. I’m also not totally sure what to do if you have some types picked from
|
I had a quick look at the pull request and it looks like you're heading down the "build a bundler" route. Can I suggest to keep things simple that you keep ts-to-zod as a compiler only? This is how typescript compiler itself works, and does not provide bundling. It works because the output directory has a mirrored structure of the input directory. Also not sure if it's helpful, but this is the script I've built using a glob pattern to produce a generated dir. I am temporarily replacing any imported identifiers with a string literal (a uuid) and after ts-to-zod has done it's things, I go back through and replace the https://gist.github.com/mattfysh/6a071d5b2150bdb6fb10be5be715402c |
Actually most of the work in this PR is to retrieve the relevant types from the import clauses and aggregate the schema in order not to modify the return of the I do agree with you that splitting the schemas up in multiple file would be a nice option to offer in the future.
Thanks for sharing, your script is interesting but it would need some polishing to be used in production. |
Quite a busy life those days, I will try to have a look when this is getting calmer. If one of those PR are working for you, please try them on your projects (the easiest is to clone the project, add your name as prefix in the package name and publish to npm 😉 ) Every feedbacks are appreciate :) Thanks for the support 😃 |
For some reasons, I had missed this issue so started working on 2 successives PRs:
|
Import support has been added to |
Thanks for building this great package! In our project, we automatically generate types for GQL queries adjacent to their definitions in That way, we always have a zod schema available to parse GQL responses with — which we need specifically because we sometimes cache query results on redis, and don't necessarily want to blindly trust that the cached data has the required shape at runtime. As-is, I understand that the only way to do this with this package would be to dynamically generate an ephemeral config that lists all the generated files explicitly, and discarding it after the zod types were generated. That's a bit convoluted. I was hoping that I could just configure the package to run for all files matching a glob, and an output filename relative to the matched input file's location. Does this match your vision? |
glob sounds like a nice idea |
My vision for the next step (because that would ease my work 😅) was to generate for all files in a given directory (or set of files), with
That would be an interesting next step: it would work out-of-the-box only for "independent" files. If the files matching the glob reference each other in a way, then validation would fail. |
In our case, the files are spread all over the repo, because they're generated adjacent to the query definitions. So the glob would be something like
Again in our case, the files don't reference each other, but they do reference a "global types file" which has the basic GQL types in it, like scalars etc. I'm not sure how unique this setup is, but it's the result of using graphql-codegen with the The graphql codegen config in question is here ... as I'm writing this, I'm starting to realize that having a graphql-codegen plugin that uses this package to transform types to schemas would probably be the neatest solution, and would offload all the complex glob matching logic to graphql-codegen itself. For our specific usecase at least. |
Feature description
So far, we are just supporting types declared in one file. The plan will be to follow any
import
statement.To solve different use cases, we should provide different resolving options:
"flat"
-> all the dependencies are flatten in one output file (perfect for Mark types for schema generation #30 usecase)"multi"
-> we have a 1-1 mapping between (perfect for Circular Dependencies Error when there are none #70 usecase)Input
Output (flat)
Output (multi)
Related issues
#30 #70
The text was updated successfully, but these errors were encountered: