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

Change gen usage #1115

Merged
merged 33 commits into from
Nov 18, 2021
Merged

Change gen usage #1115

merged 33 commits into from
Nov 18, 2021

Conversation

ghostdogpr
Copy link
Owner

TL;DR
gen[A] becomes gen[R, A]

For Scala 2:
You no longer need to worry about calling the right gen (from Schema vs GenericSchema), you can simply use Schema.gen everywhere. It now takes 2 type parameters R and A but you can usually omit them if you explicitly define the return type of your schema.

object schema extends GenericSchema[MyEnv]
import schema._

implicit val queriesSchema: Schema[MyEnv, Queries] = Schema.gen
// or
implicit val queriesSchema = Schema.gen[MyEnv, Queries]

If you use genMacro, you still need to do it on GenericSchema.

For Scala 3:
It is no longer necessary to use GenericSchema[R]. You can simply use Schema.gen when you need to explicitly derive a schema. Caliban will be able to derive a Schema[R, A] directly from that.

If your R is not Any, you need to pass it to the graphQL function, unless you already have a Schema[R, Query] in scope:

val api = graphQL[MyEnv, Queries, Unit, Unit](RootResolver(queries))
// or
implicit val queriesSchema: Schema[MyEnv, Queries] = Schema.gen
val api = graphQL(RootResolver(queries))

If you want to see the code generated by the derivation, you can use Schema.genDebug instead. It will print the generated code to the console when compiling.

Base automatically changed from scala3 to master November 18, 2021 06:37
# Conflicts:
#	.circleci/config.yml
#	adapters/http4s/src/test/scala/caliban/Http4sAdapterSpec.scala
#	adapters/play/src/test/scala/caliban/PlayAdapterSpec.scala
#	examples/src/main/scala/example/federation/FederatedApi.scala
#	federation/src/main/scala/caliban/federation/Federation.scala
@ghostdogpr ghostdogpr merged commit 58334d3 into master Nov 18, 2021
@ghostdogpr ghostdogpr deleted the new-gen branch November 18, 2021 08:05
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 24, 2022
* Upgrade Scala 3 to 3.1.0

* Give federation a little help

* Simplify

* Remove weird trick

* Update CI

* Fix name

* Simplify

* Simplify

* fmt

* Simplify

* Add R parameter to gen

* fmt

* Simplify

* Cleanup

* Fix examples

* Cleanup

* Prettify

* Simplify

* Fix federation

* Scala 3 fix

* Proper fix
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 27, 2022
* Upgrade Scala 3 to 3.1.0

* Give federation a little help

* Simplify

* Remove weird trick

* Update CI

* Fix name

* Simplify

* Simplify

* fmt

* Simplify

* Add R parameter to gen

* fmt

* Simplify

* Cleanup

* Fix examples

* Cleanup

* Prettify

* Simplify

* Fix federation

* Scala 3 fix

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

Successfully merging this pull request may close these issues.

1 participant