-
Hi everybody I am new to GraphQL Code Generator. I am working on a next project querying WordPress data from a GraphQL endpoint. I have a folder structure with various queries and fragments placed in *.ts files in subfolders inside a "data" folder in my project. The queries are working and I get the data. However, codegen will fail after Loading GraphQL schemas and -documents during generation. I get this error:
and then a long list of my failing fragments. How do I import fragments correctly? Here is an example on how I do things today:
So far I have only tried with a basic codegen.yml file (schema is a live endpoint - but works fine):
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Alright, sat down and really took a deep dive into the graphql-code-generator documentation and now finally got the typedDocumentNode up and running. I somehow missed some important steps like placing the actual queries inside *.graphql files. But have to admit this is really awesome! |
Beta Was this translation helpful? Give feedback.
-
@dotansimha and anyone else trying to get fully typed datasets in next.js I finally found a way to do this in Next. I used quite a bit of time on the "Typescript Apollo Nextjs" plugin, and although it offers a lot of extra ways to set up the file(s) it also offers A LOT of extra complexity. Most developers will probably be better of just using TypedDocumentNode in most simple cases. Here is HOW I got it working:
Here is an example page component:
"Get_PageDocument" is provided by TypedDocumentNode. If you hover "data" in the getStaticProps component you will get the name of the type you need to import for "data" in the main Page Component (in this example "Get_PageQuery"). This would probably be helpful for others working with next.js and trying to get fully typed datasets |
Beta Was this translation helpful? Give feedback.
@dotansimha and anyone else trying to get fully typed datasets in next.js
I finally found a way to do this in Next. I used quite a bit of time on the "Typescript Apollo Nextjs" plugin, and although it offers a lot of extra ways to set up the file(s) it also offers A LOT of extra complexity.
Most developers will probably be better of just using TypedDocumentNode in most simple cases.
Here is HOW I got it working:
Here is an example page co…