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

how to generate types.rs this file ? #1

Open
athxx opened this issue Jun 2, 2023 · 4 comments
Open

how to generate types.rs this file ? #1

athxx opened this issue Jun 2, 2023 · 4 comments

Comments

@athxx
Copy link

athxx commented Jun 2, 2023

I'm using your template as base, but I don't know how to generate types.rs this file, would you might teach me how to generate this file ?

as your types.rs annotations, I wondering how to use prisma to generate this file, thank you

// Note: ideally, I would not need this file at all. I would just use the generated
// struct definitions from the prisma client, however with async-graphql I need
// to derive some traits to make it work.
@aaronleopold
Copy link
Owner

Hello, sorry this got lost in my notifications!

You use cargo prisma generate to create the prisma.rs file. The types.rs file is not a generated file, and it really just redefines the prisma models as separate structs with some macro derives so that async-graphql can properly work with them. With only a couple types in the template, i.e. Post and User, I just shoved them (and all of the From trait definitions) into one file (types.rs) for simplicity. But realistically, with a real world service, you would want to split it up into separate modules.

@coopbri
Copy link

coopbri commented Jul 1, 2023

Are there any GraphQL projects in the Rust ecosystem you guys are aware of that allow directly using the generated PCR types without manually creating these additional types? This automatic generation is something I've grown very accustomed to in the Node/JS/TS ecosystem and would love to map it over to Rust!

@aaronleopold
Copy link
Owner

aaronleopold commented Jul 1, 2023

Not that I’m aware of. I vaguely remember the PCR developer mentioning that him and the developer of rspc had thoughts/plans for some sort of GraphQL adapter/library. But, it was about a year ago now 😄 you can probably pop in their discord to ask

@coopbri
Copy link

coopbri commented Jul 1, 2023

Hahah, thanks for the tip, ironically I asked a similar question in the PCR repo: Brendonovich/prisma-client-rust#347

😂

Not a huge deal. Thanks anyways man!

EDIT: relevant:

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

No branches or pull requests

3 participants