-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
modules/sangria/src/main/scala/derevo/sangria/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package derevo | ||
|
||
import derevo.Derivation | ||
import derevo.delegating | ||
import derevo.Derevo | ||
import _root_.sangria.schema._ | ||
import _root_.sangria.macros.derive._ | ||
|
||
package object sangria { | ||
|
||
type Ctx = Any | ||
type CtxObjectType[A] = ObjectType[Ctx, A] | ||
type DeriveObjectSettingNoContext[A] = DeriveObjectSetting[Ctx, A] | ||
|
||
@delegating("sangria.macros.derive.deriveInputObjectType") | ||
object inputObjectType extends Derivation[InputObjectType] { | ||
|
||
def apply[A](arg: DeriveInputObjectSetting*): InputObjectType[A] = | ||
macro Derevo.delegateParamsV[InputObjectType, A, DeriveInputObjectSetting] | ||
|
||
} | ||
|
||
@delegating("sangria.macros.derive.deriveObjectType") | ||
object objectType extends Derivation[CtxObjectType] { | ||
|
||
def apply[A](arg: DeriveObjectSettingNoContext[A]*): CtxObjectType[A] = | ||
macro Derevo.delegateParamsV[CtxObjectType, A, DeriveObjectSettingNoContext[A]] | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
modules/sangria/src/test/scala/derevo/sangria/SangriaDerivationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package derevo.sangria | ||
|
||
import derevo.derive | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sangria.schema.InputObjectType | ||
import sangria.macros.derive.InputObjectTypeName | ||
import sangria.macros.derive.ExcludeInputFields | ||
import sangria.macros.derive.ObjectTypeName | ||
import sangria.macros.derive.RenameField | ||
|
||
class SangriaDerivationSpec extends AnyFlatSpec with Matchers { | ||
"Sangria input object derivation" should "derive input object without customization" in { | ||
val derived = implicitly[InputObjectType[SangriaDerivationSpec.Input]] | ||
|
||
assertResult("Input")(derived.name) | ||
derived.fields.map(_.name) should contain theSameElementsAs List("stringParam", "intParam") | ||
} | ||
|
||
it should "derive input object with customization" in { | ||
val derived = | ||
implicitly[InputObjectType[SangriaDerivationSpec.InputCustom]] | ||
|
||
assertResult("Renamed")(derived.name) | ||
derived.fields.map(_.name) should contain theSameElementsAs List("stringParam", "fooInner") | ||
} | ||
|
||
"Sangria object derivation" should "derive object without customization" in { | ||
val derived = | ||
implicitly[CtxObjectType[SangriaDerivationSpec.Response]] | ||
|
||
assertResult("Response")(derived.name) | ||
derived.fields.map(_.name) should contain theSameElementsAs List("data") | ||
} | ||
|
||
"Sangria object derivation" should "derive object with customization" in { | ||
val derived = | ||
implicitly[CtxObjectType[SangriaDerivationSpec.ResponseCustom]] | ||
|
||
assertResult("RenamedResponse")(derived.name) | ||
derived.fields.map(_.name) should contain theSameElementsAs List("content") | ||
} | ||
} | ||
|
||
object SangriaDerivationSpec { | ||
@derive(inputObjectType()) case class Input(stringParam: String, intParam: Int) | ||
@derive(inputObjectType(InputObjectTypeName("Renamed"), ExcludeInputFields("intParam"))) case class InputCustom( | ||
stringParam: String, | ||
intParam: Int, | ||
fooInner: Input | ||
) | ||
|
||
@derive(objectType()) | ||
case class Response(data: String) | ||
|
||
@derive(objectType(ObjectTypeName("RenamedResponse"), RenameField("data", "content"))) | ||
case class ResponseCustom(data: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters