Skip to content

PartialSchema Type extensions #93

Open

Description

@cshadek

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.

Activity

  1. changed the title [-]SubSchema Type extensions[/-] [+]PartialSchema Type extensions[/+] on Jan 30, 2023
  2. cshadek commented on Jan 30, 2023

    @cshadek
    ContributorAuthor

    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.

  3. d-exclaimation commented on Jan 30, 2023

    @d-exclaimation
    Member

    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.

  4. cshadek commented on Jan 30, 2023

    @cshadek
    ContributorAuthor

    @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?

  5. d-exclaimation commented on Jan 30, 2023

    @d-exclaimation
    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

  6. NeedleInAJayStack commented on Jan 31, 2023

    @NeedleInAJayStack
    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 ;)

  7. cshadek commented on Jan 31, 2023

    @cshadek
    ContributorAuthor

    @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?

  8. d-exclaimation commented on Jan 31, 2023

    @d-exclaimation
    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

  9. cshadek commented on Feb 20, 2023

    @cshadek
    ContributorAuthor

    @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.

  10. d-exclaimation commented on Feb 20, 2023

    @d-exclaimation
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions