-
Notifications
You must be signed in to change notification settings - Fork 18
Allow codegen for non-gatsby schemas #39
Comments
Hi @ricokahler, thanks for coming back with another interesting issue (I still owe you a response in #29!)
I really like that! However it looks like graphql-toolkit (the lib that scan code files for graphql documents) doesn't expose an api for filter/ignore graphql tags, and the returned graphql documents also don't contain information of their graphql tags & libraries. We'd need to open an issue at graphql-toolkit & see if the folks there want to support this. With the current setup, we can only filter documents by theirs file paths and operation type :/ which doesn't seem too helpful. |
That makes sense. I had a feeling I'd have to open another upstream lol That's good info though. Looking at the repo, it seems like |
I was doing a bit of digging in that repo and it seems like they do actually expose an API for picking the particular tags. 👇 export interface GraphQLTagPluckOptions {
modules?: Array<{ name: string; identifier?: string }>;
gqlMagicComment?: string;
globalGqlIdentifierName?: string | string[];
} And we can override this config via options to So it seems it is actually possible to codegen for different schemas based on the tag type 🎉 Here is a very rough idea of how I'm thinking we could implement this. 1. override the default
|
Wow, great work! For whatever reasons, when I saw that It's definitely possible to get this feature out then. I think the config you propose makes sense. Maybe add an option to declare more file paths as well. I think the steps could be:
And then I'll need to start adding tests as well 😅 Let me know what you think and if you'd have time to help with these! |
Yeah I have some time. I can probably get a PR to you within the next few days if you'll take it. I can also set up jest for the repo in a separate PR if you want too. |
Thanks @ricokahler, I'll take them all — please send PRs! If you know a typescript + gatsby + apollo opensource projects / starter that we can test this plugin with, please share as well. |
@devuxer @kokokenada @imanbee thanks for leaving a like on the parent issue. Just want to let you know this feature is now supported in v2.6.0, thanks to @kije! |
I apologize if this issue is specific however I don't know where else to post about it.
It's sort of an issue with
graphql-codegen
but also specific to codegen in a gatsby context via this plugin so I'll start here 😅Please let me know if I missed something!
The issue
Using the
@apollo/client
(v3.0.0-beta.32
), requires you import thegql
tag from apollo like so:The issue is, when I do this, graphql-codegen will try to create types for this query using the Gatsby schema. This is an issue because the Apollo client I have set up should point to a different graphql schema than the schema created via gatsby during build time.
The workaround
I have a temporary workaround of importing
gql
viarequire
like so:Recommendations
At the minimum, it would be nice if it were possible to add some sort of way to ignore codegen for particular patterns (e.g. importing from
@apollo/client
). This way this plugin stays focused on just doing codegen for gatsby related queries.Going all in, we could work towards this plugin officially supporting the Apollo client via allowing an additional non-gatsby schema and generating a different types file per the type of graphql tag. I'm not too sure how to get this working or even it makes sense but hopefully this will inspire.
Thanks for any help!
The text was updated successfully, but these errors were encountered: