Skip to content

Commit

Permalink
Remove unnecessary param from Validator.prepare (#2291)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Jun 18, 2024
1 parent bedb71d commit 3f14b94
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ValidationBenchmark {

private val runtime = Runtime.default

def run[A](zio: Task[A]): A = Unsafe.unsafe(implicit u => runtime.unsafe.run(zio).getOrThrow())
def toSchema[R](graphQL: GraphQL[R]): IO[CalibanError, (RootSchema[R], RootType)] =
def run[A](zio: Task[A]): A = Unsafe.unsafe(implicit u => runtime.unsafe.run(zio).getOrThrow())
def toSchema[R](graphQL: GraphQL[R]): IO[CalibanError, RootType] =
graphQL.validateRootSchema.map { schema =>
schema -> RootType(
RootType(
schema.query.opType,
schema.mutation.map(_.opType),
schema.subscription.map(_.opType)
Expand All @@ -38,11 +38,11 @@ class ValidationBenchmark {
val parsedDeepWithArgsQuery = run(Parser.parseQuery(deepWithArgsQuery))
val parsedIntrospectionQuery = run(Parser.parseQuery(ComplexQueryBenchmark.fullIntrospectionQuery))

val (simpleSchema, simpleType) = run(
val simpleType = run(
toSchema(graphQL[Any, SimpleRoot, Unit, Unit](RootResolver(NestedZQueryBenchmarkSchema.simple100Elements)))
)

val (multifieldSchema, multifieldType) =
val multifieldType =
run(
toSchema(
graphQL[Any, MultifieldRoot, Unit, Unit](
Expand All @@ -51,7 +51,7 @@ class ValidationBenchmark {
)
)

val (deepSchema, deepType) =
val deepType =
run(
toSchema(
graphQL[Any, DeepRoot, Unit, Unit](
Expand All @@ -60,7 +60,7 @@ class ValidationBenchmark {
)
)

val (deepWithArgsSchema, deepWithArgsType) =
val deepWithArgsType =
run(
toSchema(
graphQL[Any, DeepWithArgsRoot, Unit, Unit](
Expand Down Expand Up @@ -106,7 +106,6 @@ class ValidationBenchmark {
.prepareEither(
parsedSimpleQuery,
simpleType,
simpleSchema,
None,
Map.empty,
skipValidation = true,
Expand All @@ -120,7 +119,6 @@ class ValidationBenchmark {
.prepareEither(
parsedMultifieldQuery,
multifieldType,
multifieldSchema,
None,
Map.empty,
skipValidation = true,
Expand All @@ -134,7 +132,6 @@ class ValidationBenchmark {
.prepareEither(
parsedDeepQuery,
deepType,
deepSchema,
None,
Map.empty,
skipValidation = true,
Expand All @@ -148,7 +145,6 @@ class ValidationBenchmark {
.prepareEither(
parsedIntrospectionQuery,
Introspector.introspectionRootType,
simpleSchema,
None,
Map.empty,
skipValidation = true,
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/caliban/GraphQL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ trait GraphQL[-R] { self =>
Validator.prepareEither(
doc,
typeToValidate(doc),
schemaToExecute(doc),
operationName,
coercedVars,
config.skipValidation,
Expand Down
18 changes: 8 additions & 10 deletions core/src/main/scala/caliban/validation/Validator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,24 @@ object Validator {
*
* @see [[prepareEither]] for a variant that returns an Either instead
*/
def prepare[R](
def prepare(
document: Document,
rootType: RootType,
rootSchema: RootSchema[R],
operationName: Option[String],
variables: Map[String, InputValue],
skipValidation: Boolean,
validations: List[QueryValidation]
): IO[ValidationError, ExecutionRequest] = ZIO.fromEither(
prepareEither(document, rootType, rootSchema, operationName, variables, skipValidation, validations)
prepareEither(document, rootType, operationName, variables, skipValidation, validations)
)(Trace.empty)

/**
* Prepare the request for execution.
* Fails with a [[caliban.CalibanError.ValidationError]] otherwise.
*/
def prepareEither[R](
def prepareEither(
document: Document,
rootType: RootType,
rootSchema: RootSchema[R],
operationName: Option[String],
variables: Map[String, InputValue],
skipValidation: Boolean,
Expand Down Expand Up @@ -140,19 +138,19 @@ object Validator {
operation.flatMap { op =>
(op.operationType match {
case Query =>
Right(rootSchema.query)
Right(rootType.queryType)
case Mutation =>
rootSchema.mutation.toRight(ValidationError("Mutations are not supported on this schema", ""))
rootType.mutationType.toRight(ValidationError("Mutations are not supported on this schema", ""))
case Subscription =>
rootSchema.subscription.toRight(ValidationError("Subscriptions are not supported on this schema", ""))
}).map(operation =>
rootType.subscriptionType.toRight(ValidationError("Subscriptions are not supported on this schema", ""))
}).map(opType =>
ExecutionRequest(
F(
op.selectionSet,
fragments,
variables,
op.variableDefinitions,
operation.opType,
opType,
document.sourceMapper,
op.directives,
rootType
Expand Down
1 change: 0 additions & 1 deletion core/src/test/scala/caliban/execution/FieldSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ object FieldSpec extends ZIOSpecDefault {
req <- Validator.prepare(
doc,
rootType,
schema,
operationName = None,
Map.empty,
skipValidation = false,
Expand Down

0 comments on commit 3f14b94

Please sign in to comment.