You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
@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?
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 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.
@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
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.
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.
Activity
[-]SubSchema Type extensions[/-][+]PartialSchema Type extensions[/+]cshadek commentedon 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
SchemaBuilderandPartialSchema.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
TypeExtensiontype.d-exclaimation commentedon 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 commentedon 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
PartialSchemafeature 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 commentedon Jan 30, 2023
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 commentedon Jan 31, 2023
@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 commentedon 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 commentedon Jan 31, 2023
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
.addor.usefunction 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.buildis calledcshadek commentedon 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 commentedon Feb 20, 2023
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.