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

V8. Generated types location #1220

Open
ziimakc opened this issue Oct 25, 2024 · 4 comments
Open

V8. Generated types location #1220

ziimakc opened this issue Oct 25, 2024 · 4 comments

Comments

@ziimakc
Copy link

ziimakc commented Oct 25, 2024

Maybe it makes sense to move generated types into node_modules and expose them like prisma does?

import { Generated } from "graffle/generator";

const data: Generated.UserQuery = {...}

Reasoning:

  • No need to commit generated types and commit regenerated types on each new query/schema change.
  • Generated types are ugly, unreadable and not formatted :)
  • Generated types use PascalCase while backend mostly uses dash-case for file naming.
  • It will be simpler.
@ziimakc ziimakc changed the title V8. Generated types V8. Generated types location Oct 25, 2024
@jasonkuhrt
Copy link
Member

If you install dprint it will be formatted. Regarding file naming conventions I will expose an option for that.

Regarding how Prisma does it, I'm not closed to that however it's more complex for many reasons so wouldn't prioritize it now.

You could emit to node_modules/@types/graffle-generated, but that wouldn't solve the runtime parts that still need importing for some features.

@jasonkuhrt
Copy link
Member

Related #1144

@ziimakc ziimakc closed this as completed Oct 25, 2024
@jasonkuhrt
Copy link
Member

@ziimakc Let's keep this open for now:

  • bring option to control file case
  • explore node_modules emit in the future (either as guide content or full blown feature)

@jasonkuhrt
Copy link
Member

In order to output to node_modules we would need to consider a few things:

  • How the static exports of graffle are modified to accommodate the generation. Literally we'd probably have to rewrite one or more entry points in graffle or that via some indirection.

  • How will multiple schemes be supported. we could for example start to append new client entry points:

     import { One } from 'graffle/clients/one'
     import { Two } from 'graffle/clients/two'
     // ...

    This would require a manipulation of the exports field on the package.json as well.

  • The really hard part has to do with having the package managers, bundlers, etc. not lose track of the generated contents. I would talk to @millsp. I think you can do something like emit to node_modules/.cache which all package managers will NOT touch. But, we'd still have to write into node_modules/graffle/... to make it attempt to import from there etc. And anything we do there is what becomes fragile. Maybe we could rely on the Node resolution algorithm along with dynamic ESM import, for example ... import('../.cache/...') but then we've lost the static aspect of the library after generation which is not good for tree-shaking etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants