GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
526 stars 66 forks source link

Is there a way to create parts of the schema in another file or function? #51

Closed cshadek closed 1 year ago

cshadek commented 3 years ago

Is there a way to create parts of the schema in another file or function, similar to SwiftUI?

 init(resolver: Resolver) throws {
        ...
        self.schema = try Schema<RootAPI, UserContext> {

               OtherSchema()
               TypeDeclaredElseWhere()

        }
}

Where OtherSchema would be another schema or group of fields from another file or function.

cshadek commented 3 years ago

If it helps, my current use case is as follows: I have 2 schemas (one for public access and one for authenticated access). I would like to have a set of types and queries that are shared by both of these schemas. So ideally, I would declare the shared parts of the schema in one place and use them in both schemas. Is this possible?

paulofaria commented 3 years ago

Hello, @cshadek. I'm afraid this is not possible now. However, I think it should be easy to implement it by adding an initializer that takes a fully formed schema as a base and extends it. Maybe even a list of schemas. Are you willing to give it a try? Otherwise I can add that in the next release. Its release date is TBD, though.

cshadek commented 3 years ago

@paulofaria, sure I can give it a try. Are you able to provide any pointers for me?

NeedleInAJayStack commented 1 year ago

This has been resolved by https://github.com/GraphQLSwift/Graphiti/pull/87