From 3f14b946c43c4ddec8c661d83a0a1884eecf5cbf Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:45:06 +1000 Subject: [PATCH] Remove unnecessary param from `Validator.prepare` (#2291) --- .../validation/ValidationBenchmark.scala | 18 +++++++----------- core/src/main/scala/caliban/GraphQL.scala | 1 - .../scala/caliban/validation/Validator.scala | 18 ++++++++---------- .../scala/caliban/execution/FieldSpec.scala | 1 - 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/benchmarks/src/main/scala/caliban/validation/ValidationBenchmark.scala b/benchmarks/src/main/scala/caliban/validation/ValidationBenchmark.scala index 9829494ac..3b0cbe52f 100644 --- a/benchmarks/src/main/scala/caliban/validation/ValidationBenchmark.scala +++ b/benchmarks/src/main/scala/caliban/validation/ValidationBenchmark.scala @@ -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) @@ -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]( @@ -51,7 +51,7 @@ class ValidationBenchmark { ) ) - val (deepSchema, deepType) = + val deepType = run( toSchema( graphQL[Any, DeepRoot, Unit, Unit]( @@ -60,7 +60,7 @@ class ValidationBenchmark { ) ) - val (deepWithArgsSchema, deepWithArgsType) = + val deepWithArgsType = run( toSchema( graphQL[Any, DeepWithArgsRoot, Unit, Unit]( @@ -106,7 +106,6 @@ class ValidationBenchmark { .prepareEither( parsedSimpleQuery, simpleType, - simpleSchema, None, Map.empty, skipValidation = true, @@ -120,7 +119,6 @@ class ValidationBenchmark { .prepareEither( parsedMultifieldQuery, multifieldType, - multifieldSchema, None, Map.empty, skipValidation = true, @@ -134,7 +132,6 @@ class ValidationBenchmark { .prepareEither( parsedDeepQuery, deepType, - deepSchema, None, Map.empty, skipValidation = true, @@ -148,7 +145,6 @@ class ValidationBenchmark { .prepareEither( parsedIntrospectionQuery, Introspector.introspectionRootType, - simpleSchema, None, Map.empty, skipValidation = true, diff --git a/core/src/main/scala/caliban/GraphQL.scala b/core/src/main/scala/caliban/GraphQL.scala index be663847d..591acd01f 100644 --- a/core/src/main/scala/caliban/GraphQL.scala +++ b/core/src/main/scala/caliban/GraphQL.scala @@ -142,7 +142,6 @@ trait GraphQL[-R] { self => Validator.prepareEither( doc, typeToValidate(doc), - schemaToExecute(doc), operationName, coercedVars, config.skipValidation, diff --git a/core/src/main/scala/caliban/validation/Validator.scala b/core/src/main/scala/caliban/validation/Validator.scala index 9fba23676..183313cea 100644 --- a/core/src/main/scala/caliban/validation/Validator.scala +++ b/core/src/main/scala/caliban/validation/Validator.scala @@ -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, @@ -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 diff --git a/core/src/test/scala/caliban/execution/FieldSpec.scala b/core/src/test/scala/caliban/execution/FieldSpec.scala index e046a67ae..8ad32032d 100644 --- a/core/src/test/scala/caliban/execution/FieldSpec.scala +++ b/core/src/test/scala/caliban/execution/FieldSpec.scala @@ -61,7 +61,6 @@ object FieldSpec extends ZIOSpecDefault { req <- Validator.prepare( doc, rootType, - schema, operationName = None, Map.empty, skipValidation = false,