-
Notifications
You must be signed in to change notification settings - Fork 66
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
Adds a SchemaBuilder type for modular schema creation #87
Adds a SchemaBuilder type for modular schema creation #87
Conversation
a8288ac
to
b81a57f
Compare
Are these additive changes? Didn't have enough time to properly look into it, yet. |
Yup, purely additive. |
Have you tried implementing it using result builders? I think it fits better with Swift when comparing it to fluent builders. |
Can you split up result builder definitions or do they always need to be defined in a single contiguous block? I'll admit, I'm not a result builder expert. My goal with this was to allow schemas to be defined over a number of different functions, files, or even packages, because my schema definitions get REALLY huge and unwieldy when I have to keep them in a single block. Builders like Vapor's RouteBuilder or SQLKit's SQLPredicateBuilder achieve that goal pretty well. For example, we could have a project with the 3 files below, where functionality is separated effectively: # Main.swift
let builder = SchemaBuilder<Res, Ctx>()
addHello(to: builder)
addGoodbye(to: builder)
let schema = try builder.build()
print(schema.execute("{ goodbye }", ...)) // Prints: {"goodbye": "for now"} # Hello.swift
extension Res {
func hello() -> String {
"world"
}
}
func addHello(to builder: SchemaBuilder<Res, Ctx>) {
builder.addQuery(
Field("hello", at: \.hello)
)
} # Goodbye.swift
extension Res {
func goodbye() -> String {
"for now"
}
}
func addGoodbye(to builder: SchemaBuilder<Res, Ctx>) {
builder.addQuery(
Field("goodbye", at: \.goodbye)
)
} I didn't know how to accomplish something like this with a |
Also, just to be clear, the |
Hey, Jay! Sure, I'll give you an update this week! |
Hey @paulofaria, any updates on this? I'd be happy to make the changes if you can get me an example of the multi-file result-builder schema construction! |
Sorry! I'm moving to a new house, so things are chaotic around here. I'll try to find the time, though. Should be straight forward. |
Hey, @NeedleInAJayStack. Can you please check you reddit DMs? 😁 |
@paulofaria Hah, what? I'm not on Reddit, but you can always reach me at NeedleInAJayStack@protonmail.com |
Any updates on this? |
b81a57f
to
05f09d5
Compare
I think @paulofaria was going to send me an example of a distributed ResultBuilder |
Really sorry about the delay. @NeedleInAJayStack can I update this PR directly, with the result builder approach? I think it's easier. |
@paulofaria No worries! Sure, feel free to edit this directly or on your own branch of my work. |
Hey, I’m really sorry about this. I think it’s best to merge this as is and improve later, if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fd6dee3
to
691e450
Compare
Awesome, thanks Paulo! Mind approving again after my rebase? |
@NeedleInAJayStack thank you very much for this, Jay! |
This adds a
SchemaBuilder
, which enables much more modular schema creation. By breaking up the schema definition, different parts of the schema could be created in different functions, files, or even packages.