-
Notifications
You must be signed in to change notification settings - Fork 75
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 #313
Comments
Hello @XPOL555, In the documentation the types are an example of what you might have in your nuxt app. Those are not auto-generated, you have to define them yourself by creating a export interface Restaurant {
id: number
name: string
} |
Thank you @benjamincanac I've used graphql-codegen a lot and this might be interesing. I hate passing through graphql but it helps in this case. This is a basic import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
overwrite: true,
schema: "schema.graphql",
documents: "graphql/**/*.graphql",
generates: {
"gql.ts": {
plugins: [
"typescript"
]
}
}
};
export default config; Then you run So you can import the type from that file like this <script lang="ts" setup>
import {Frontpage} from "~/gql";
const { findOne } = useStrapi<Frontpage>()
const {data} = await findOne<Frontpage>('frontpage')
console.log(data)
</script> ℹ️ Be sure to have the strapi graphql plugin enabled and the route /graphql exposed. You can use a schema url also (see the docs) |
@XPOL555 Thanks for your example! This would be a nice addition to the advanced section of the documentation if you have some spare time 😊 |
In documentation there is a reference to types: https://strapi.nuxtjs.org/usage#types
Also in asyndata https://strapi.nuxtjs.org/advanced#async-data
there is a reference to
~/types
Where is this file generated? Documentation is totally unclear in this part for me.
The text was updated successfully, but these errors were encountered: