Skip to content
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

Extending root-types #81

Closed
JoviDeCroock opened this issue Nov 3, 2023 · 4 comments
Closed

Extending root-types #81

JoviDeCroock opened this issue Nov 3, 2023 · 4 comments

Comments

@JoviDeCroock
Copy link

Hey,

I have been trying out garph and been loving the idea's behind it, however I have run into a few missing things for organising bigger structures.

I see the similarity with both #39 and #78 and if it's too similar feel free to close this issue.

That being said, I was looking at trying out this project and tried my regular approach of doing types/User and types/Todo, where both of these define a g.type('Query') which seemed to override one another 😅 I think it would be really beneficial if we could extend the Query type in multiple files so we don't have to import everything from everywhere.

I guess one of the limitations here would be the type-system, y'all have something great going with the InferClient, ... If I can help out anywhere feel free to say so as well

@mishushakov
Copy link
Member

mishushakov commented Nov 5, 2023

Thank you so much for the kind words!
It's not really possible to extend a type from a different file. Type definitions can't really be "updated" in TypeScript. The way this is done currently is by returning a modified class.

Basically you will end up with two variants of the same root type.

We can make the type extendable in the same file (just like the implements modifier). You will still have to import the types from elsewhere into the main file though, if you want the changes to be available globally. Pothos has a similar issue, so there's no way around it as it's a TypeScript limitation 🤷

@mishushakov
Copy link
Member

Btw. Can I ask what other framework, if any you're using with your current approach?

@JoviDeCroock
Copy link
Author

I managed to pull it off with pothos by doing addQueryField 😅 missing the inferClientTypes though

@mishushakov
Copy link
Member

I have added an experimental extend modifier in 0.6.3.
More: https://garph.dev/docs/guide/schemas.html#extend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants