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

PartialSchema Type extensions #93

Open
cshadek opened this issue Jan 30, 2023 · 9 comments
Open

PartialSchema Type extensions #93

cshadek opened this issue Jan 30, 2023 · 9 comments

Comments

@cshadek
Copy link
Contributor

cshadek commented Jan 30, 2023

I love the new SubSchema feature from @d-exclaimation!

I think it would be useful to have the ability to extended Types from one SubSchema in another SubSchema.

This would be a natural extension to the new declarative SubSchema feature and would allow you to break up a GraphQL type across multiple packages similar to Swift's extension feature.

@cshadek cshadek changed the title SubSchema Type extensions PartialSchema Type extensions Jan 30, 2023
@cshadek
Copy link
Contributor Author

cshadek commented Jan 30, 2023

One idea might be to naturally combine Types if a Type is declared multiple times in a schema or over multiple schemas. I'm not entirely sure how this would work with the current SchemaBuilder and PartialSchema.

You potentially run into an issue where a field on a type is declared twice and that might be a little tricky.

Another option would be to have a TypeExtension type.

@d-exclaimation
Copy link
Member

d-exclaimation commented Jan 30, 2023

I have seen this before from the Node.js ecosystem, with graphql-nexus but it somewhat relies on codegen.

The difficult part that I noticed right away would be implementing this in a type safe manner since we won't know the generic ObjectType of that specific Type declaration ahead of time.

Furthermore, I think GraphQL spec's object extensions would solve this. It would probably make sense to go for about it this way, although I am not 100% sure how difficult it would be.

@cshadek
Copy link
Contributor Author

cshadek commented Jan 30, 2023

@NeedleInAJayStack, @d-exclaimation, is this a change that would need to happen at the GraphQL level, or can this be isolated to Graphiti? It would definitely make the declarative PartialSchema feature much more powerful and allow us to highly modularize our resolvers and schema declarations.

Is the type safe manner really an issue because the type would be defined at compile time right?

@d-exclaimation
Copy link
Member

Adding support for the spec's object extensions would need to also happen at GraphQL level. I have seen some work on adding support for federation which relies on object extensions, but not sure the status on that.

In terms of adding this capability just on Graphiti level, I'll definitely have a look over the week and see if I can work it out

@NeedleInAJayStack
Copy link
Member

@cshadek If this is high priority for you and you have some free cycles, we sure wouldn't say no to a merge request ;)

@cshadek
Copy link
Contributor Author

cshadek commented Jan 31, 2023

@NeedleInAJayStack haha I'm always happy to help - just not that sure where to begin with this one.

I feel like it has to be a change at the GraphQL level and not Graphiti unless we can change how SchemaBuilder works to allow repeat type declarations with different fields and generate the resulting type based on the sum of those fields.

Do you have any ideas on how to go about this?

@d-exclaimation
Copy link
Member

@NeedleInAJayStack haha I'm always happy to help - just not that sure where to begin with this one.

I feel like it has to be a change at the GraphQL level and not Graphiti unless we can change how SchemaBuilder works to allow repeat type declarations with different fields and generate the resulting type based on the sum of those fields.

Do you have any ideas on how to go about this?

My first thought how this could be done is changing the SchemaBuilder typesComponent property from an array to something like map of the type name and the fields, and as the .add or .use function is called check if the type already exists in the map, just append the fields from the declaration, and rebuild the type at the end when .build is called

@cshadek
Copy link
Contributor Author

cshadek commented Feb 20, 2023

@d-exclaimation @NeedleInAJayStack,

I saw that @samisuteria just added federation, which looks awesome! Does that mean this is solved now? I haven't yet had a chance to try out federation.

@d-exclaimation
Copy link
Member

No, not yet. The addition of federation support excluded implementation for code first directives and object extensions. I think @samisuteria is working on adding directives.

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

No branches or pull requests

3 participants