-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Automatic TypeScript Definitions Generation #14185
Comments
CC: @pieh I recall you having something similar to this if I am not mistaken |
@Siyfion I'm not sure if this still works - but you can try checking https://github.com/pieh/gatsby-query-result-type-gen |
Yep, it doesn't work anymore after some refactoring done in gatsby (as I was importing some gatsby internals there), but it probably can be updated to work again. The fragment blocker you mentioned - please check my code - I was importing "queries" directly from gatsby redux store (and not parsing your project directly). This ensures that any fragments that were used will be attached to queries (i.e. gatsby-image` fragments) |
Ah nice @pieh! Is this something that the Gatsby team would consider incorporating as an official tool in future? I really think it'd be hugely useful! |
This was one of my "weekend projects", and I don't think we really talked about it yet. Now I start to remember more when I was working on this (why I didn't make it a plugin and made "standalone" tool). apollo-codegen used different version of |
Yup, I've been on the receiving end of lots of those issues at various points over the last few months! It does seem to be a constant issue with the Apollo CLI unfortunately. Still, if Gatsby did support this tool as an official way to generate TypeScript Definitions, I'm sure there would be a fair amount of support for it ;) |
You should try using
There is currently an issue with their suggested config, so use the below config. # codegen.yml
schema: http://localhost:8000/___graphql
documents:
- ./src/**/*.{ts,tsx}
- ./node_modules/gatsby-*/**/*.js
config:
namingConvention:
enumValues: keep
generates:
./src/graphqlTypes.ts:
plugins:
- typescript
- typescript-operations |
Ooooh, that's interesting! Using programmatic API ( https://graphql-code-generator.com/docs/getting-started/#using-in-runtime ) this could really be turned into gatsby plugin I think |
Related: #2374 |
Wow, that's really cool @andykenward, though it still seems to struggle with the image fragments, eg:
Perhaps using their programmatic API we could add these "known" fragments in @pieh? |
@Siyfion is works with I've made a Gatsby Starter you can try it out "Gatsby's default starter - TypeScript" with |
@andykenward we're using |
@Siyfion I think that's to do with not being able to query the Contentful GraphQL endpoint to generate their fragments. Adding the Gatsby Plugin
|
Yeah @andykenward, it's weird because they are all there in that Edit: Ah.. I see they are all fragments on things like |
@Siyfion Setting up Perhaps using |
@andykenward but the thing is, I don't think that the So the GraphQL fragments, types, etc. must all be coming from the Gatsby plugin!? EDIT: Seems to be generated by const fixedNode = fixedNodeType({ name: `ContentfulFixed`, getTracedSVG }) |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
I've been having a lot of success with |
hey folks, run into this issue by chance -- I recently wrote a typescript plugin that does codegen automatically, using The codegen part can be its own plugin really -- I wanted to spin it out but haven't got the chance to do so yet. Give it a try if you're interested! |
The new GraphiQL 1.0 re-design work should allow plugins which I think would support adding the extra fragments |
@Siyfion about Fragments, I just copy-pasted them into the project from the plugin itself and got everything generated. If anyone wondering what is my config. Here it is. overwrite: true
schema: "${SCHEMA:schema.graphql}"
pluckConfig:
globalIdentifier: "graphql"
documents:
- "./{src,gatsby-scripts}/**/*.graphql"
- "./{src,gatsby-scripts}/**/*!(.generated).{ts,tsx}"
generates:
src/types.generated.ts:
plugins:
- "typescript"
config:
namingConvention:
enumValues: keep
src/:
preset: near-operation-file
presetConfig:
extension: .generated.ts
baseTypesPath: ./types.generated.ts
plugins:
- typescript-operations
./schema.graphql:
plugins:
- "schema-ast" Although I must admit strictness of types that are generated needs to be fixed because typings that are getting generated are way too "nullable" causing millions of |
hey, has anybody encountered incompatible types between the gatsby image fluid fragments (generated by graphql-codegen) and the gatsby-image fluid prop? => #17003 |
Hey, npm install --save gatsby-plugin-codegen I would love to hear your feedback. |
For people using Gatsby with Contentful, the problem is that Contentful, everything (Required or not) has Right now I'm having to hard-code non-null types, so not getting the expected benefits of a code generator. Hope that we get a plugin or fundamental improvement from Contentful to improve this situation with nullability. |
So what is the status of that and what is the state of the art way to integrate gatsby, graphQL, image fragments and typescript? |
Let's track this in the meta issue: #17934 |
This is soon a built-in feature to Gatsby: RFC: GraphQL TypeScript Generation |
Summary
This feature request stems from a conversation on the Gatsby discord server that I had with @DSchau in which I asked:
Basic example & Motivation
Progress so far
I have managed to get the
apollo:codegen
tool to recognise the queries Gatsby uses by changing imports toimport { graphql as gql } from 'gatsby'
, as I believe it's looking forgql
tags. However, as stated above, it struggles with the Gatsby Image fragments, as it doesn't know what they are!The text was updated successfully, but these errors were encountered: