Skip to content

Commit

Permalink
checkpoint 7 - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpdaniels committed Aug 19, 2023
1 parent 2470c11 commit da5b402
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 141 deletions.
79 changes: 38 additions & 41 deletions benchmarks/src/main/scala/caliban/GraphQLBenchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package caliban

import caliban.Data._
import caliban.parsing.Parser
import caliban.parsing.adt.Document
import caliban.rendering.{ DocumentRenderer, Renderer }
import caliban.schema.Schema.auto._
import caliban.schema.ArgBuilder.auto._
import cats.effect.IO
import edu.gemini.grackle.generic.GenericMapping
import io.circe.{ Encoder, Json }
import org.openjdk.jmh.annotations._
import sangria.execution._
Expand Down Expand Up @@ -258,40 +259,40 @@ class GraphQLBenchmarks {
import sangria.macros.derive._
import sangria.schema._

implicit val OriginEnum: EnumType[Origin] = deriveEnumType[Origin](IncludeValues("EARTH", "MARS", "BELT"))
implicit val CaptainType: ObjectType[Unit, Role.Captain] = deriveObjectType[Unit, Role.Captain]()
implicit val PilotType: ObjectType[Unit, Role.Pilot] = deriveObjectType[Unit, Role.Pilot]()
implicit val EngineerType: ObjectType[Unit, Role.Engineer] = deriveObjectType[Unit, Role.Engineer]()
implicit val MechanicType: ObjectType[Unit, Role.Mechanic] = deriveObjectType[Unit, Role.Mechanic]()
implicit val RoleType: UnionType[Unit] = UnionType(
"Role",
types = List(PilotType, EngineerType, MechanicType, CaptainType)
)
implicit val CharacterType: ObjectType[Unit, Character] = ObjectType(
"Character",
fields[Unit, Character](
Field(
"name",
StringType,
resolve = _.value.name
),
Field(
"nicknames",
ListType(StringType),
resolve = _.value.nicknames
),
Field(
"origin",
OriginEnum,
resolve = _.value.origin
),
Field(
"role",
OptionType(RoleType),
resolve = _.value.role
implicit val OriginEnum: EnumType[Origin] = deriveEnumType[Origin](IncludeValues("EARTH", "MARS", "BELT"))
implicit val CaptainType: ObjectType[Unit, Role.Captain] = deriveObjectType[Unit, Role.Captain]()
implicit val PilotType: ObjectType[Unit, Role.Pilot] = deriveObjectType[Unit, Role.Pilot]()
implicit val EngineerType: ObjectType[Unit, Role.Engineer] = deriveObjectType[Unit, Role.Engineer]()
implicit val MechanicType: ObjectType[Unit, Role.Mechanic] = deriveObjectType[Unit, Role.Mechanic]()
implicit val RoleType: UnionType[Unit] = UnionType(
"Role",
types = List(PilotType, EngineerType, MechanicType, CaptainType)
)
implicit val CharacterType: ObjectType[Unit, Character] = ObjectType(
"Character",
fields[Unit, Character](
Field(
"name",
StringType,
resolve = _.value.name
),
Field(
"nicknames",
ListType(StringType),
resolve = _.value.nicknames
),
Field(
"origin",
OriginEnum,
resolve = _.value.origin
),
Field(
"role",
OptionType(RoleType),
resolve = _.value.role
)
)
)
)

val OriginArg: Argument[Option[Origin]] = Argument("origin", OptionInputType(OriginEnum))
val NameArg: Argument[String] = Argument("name", StringType)
Expand Down Expand Up @@ -500,17 +501,13 @@ class GraphQLBenchmarks {
()
}

val calibanSchema = graphQL(Caliban.resolver)
val calibanSchemaDoc = graphQL(Caliban.resolver).toDocument

@Benchmark
def renderCaliban(): Unit = {
calibanSchema.render
}
val calibanSchema = graphQL(Caliban.resolver)
val calibanSchemaDoc = graphQL(Caliban.resolver).toDocument
val renderer: Renderer[Document] = DocumentRenderer

@Benchmark
def renderCalibanFast(): Unit =
_root_.caliban.rendering.DocumentRenderer.render(calibanSchemaDoc)
renderer.render(calibanSchemaDoc)

@Benchmark
def simpleGrackle(): Unit = {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/caliban/parsing/SourceMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ trait SourceMapper {

def getLocation(index: Int): LocationInfo

def size: Option[Int] = None

}

object SourceMapper {
Expand All @@ -32,6 +34,8 @@ object SourceMapper {
val col = index - lineNumberLookup(line)
LocationInfo(column = col + 1, line = line + 1)
}

override def size: Option[Int] = Some(source.length)
}

def apply(source: String): SourceMapper = DefaultSourceMapper(source)
Expand Down
Loading

0 comments on commit da5b402

Please sign in to comment.