Generate Types #5418
Replies: 15 comments 28 replies
-
Good idea! We already do generate types in OAS and GraphQL style. Adding TypeScript is on my want-to-have list. Are there any tools available that can already generate those types into specific languages from a shared starting point? 🤔 |
Beta Was this translation helpful? Give feedback.
-
I would love to have types for the javascript sdk automaticaly generated, like prisma does. |
Beta Was this translation helpful? Give feedback.
-
Since this is a feature that probably won't get into directus core, I wrote a extension to do just this. You can take a look here. Currently it only works with TypeScript, Python and OpenAPI, but I would love to add more languages. @Nisgrak you mentioned Go and Java. I think it would be nice to add them, but currently I am not that familiar with how typing works in those languages. Could you tell me how types should look like in those languages? |
Beta Was this translation helpful? Give feedback.
-
I would love to have this feature working in the core Directus... I love using Prisma for my Typescript projects and this little feature would make me ditch Prisma. Directus would be a powerhouse with it |
Beta Was this translation helpful? Give feedback.
-
Would love this. We're currently looking for a method to generate types from our Directus collections to consume in our other TS projects. Prisma does it very well. |
Beta Was this translation helpful? Give feedback.
-
I actually have been working for a while on this matter for python and GraphQL. https://github.com/dapalex/py-graphql-mapper I have created a quite extensive suite of tests in order to make it stable as much as possible, I tried also complex queries and mutations and so far so good. Have a look at it and I hope it will become useful. |
Beta Was this translation helpful? Give feedback.
-
Might be worth to have a look at https://github.com/maltejur/directus-extension-generate-types |
Beta Was this translation helpful? Give feedback.
-
Currently we use Prisma to generate a schema, from which Prisma can generate types including their relations. |
Beta Was this translation helpful? Give feedback.
-
Heya! Thanks for opening this feature request! This feature request has received over 15 votes from the community. This means we'll move this feature request to the Under Review state! The Core team will schedule a meeting to review this request as soon as possible. The discussion will then be approved or denied. You may or may not be invited to join this meeting with the core team. For more information, see our Feature Request Process. |
Beta Was this translation helpful? Give feedback.
-
I released an extension this morning: https://github.com/chappio/directus-extension-models It allows you to generate types for further extension development. I haven’t tested them for use with the API client as my focus is on extension development but I can’t imagine there being any issues because they are just typescript types. |
Beta Was this translation helpful? Give feedback.
-
I would be interested to know IF and, if so, how high this task is on the priority list of the Directus developers? I would be really delighted with an official solution. |
Beta Was this translation helpful? Give feedback.
-
I also had some challenges and now use Drizzle ORM with Directus and it's a very smooth experience. Did a small write up about it here: https://www.felixvemmer.com/blog/drizzle-orm-directus-typescript-sdk/ |
Beta Was this translation helpful? Give feedback.
-
npx openapi-typescript http://directus.local/server/specs/oas -o ./schema.d.ts import type { components } from './schema';
type ItemsPages = components["schemas"]["ItemsPages"]; to use globally without needing to import, make the generated schema global: declare global {
<generated code>
}
export { } This could be good to add to the docs somewhere? EDIT: I'm using this bash script to regenerate the schema automatically: oas="http://directus.local/server/specs/oas"; prev=""; while true; do current=$(curl -s $oas); if [[ "$prev" != "$current" ]]; then npx openapi-typescript $oas -o ./schema.d.ts; fi; prev="$current"; sleep
5; done |
Beta Was this translation helpful? Give feedback.
-
Does anyone know the structure of the generic |
Beta Was this translation helpful? Give feedback.
-
Related discussion I just created: tools like GraphQL Codegen already exist but their utility is limited if the GraphQL Schema is role-dependent: |
Beta Was this translation helpful? Give feedback.
-
Hi!
It's would nice to have a way of get/export the type of a api collection in Typescript, Go, Java, Python, etc, so the client using the API don't have to generate the types manually.
Thanks, you are doing a amazing job with directus!
Beta Was this translation helpful? Give feedback.
All reactions