From 71d2e3a9b69ddb5fe7a2078204ada5b6fb846377 Mon Sep 17 00:00:00 2001 From: Kyle Unverferth Date: Wed, 27 Jun 2018 12:46:44 -0600 Subject: [PATCH] Proxied documents are no longer hardcoded to the "query" operation type. --- .../directive/GraphQLDirectiveProvider.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/scala/sangria/gateway/schema/materializer/directive/GraphQLDirectiveProvider.scala b/src/main/scala/sangria/gateway/schema/materializer/directive/GraphQLDirectiveProvider.scala index 6b8d801..a504613 100644 --- a/src/main/scala/sangria/gateway/schema/materializer/directive/GraphQLDirectiveProvider.scala +++ b/src/main/scala/sangria/gateway/schema/materializer/directive/GraphQLDirectiveProvider.scala @@ -31,10 +31,11 @@ class GraphQLDirectiveProvider(implicit ec: ExecutionContext) extends DirectiveP c ⇒ { val (updatedFields, fragments, vars) = prepareOriginFields(o, c.query, c.schema, c.astFields, c.parentType) val varDefs = vars.toVector.flatMap(v ⇒ c.query.operation(c.ctx.operationName).get.variables.find(_.name == v)) - val queryOp = ast.OperationDefinition(ast.OperationType.Query, - name = Some("DelegatedQuery"), - variables = varDefs, - selections = updatedFields) + val (ot, n) = c.query.operations.map(_._2.operationType).toSeq.distinct.toList match { + case h :: Nil => (h, Some("Delegated" + h)) + case x => throw new IllegalStateException(s"Query contains operations [${x.mkString(", ")}].") + } + val queryOp = ast.OperationDefinition(operationType = ot, name = n, variables = varDefs, selections = updatedFields) val query = ast.Document(queryOp +: fragments) ctx.request(schema, query, c.ctx.queryVars, c.astFields.head.outputName).map(value ⇒ @@ -183,4 +184,4 @@ object GraphQLDirectiveProvider { arguments = Args.Fields :: Nil, locations = Set(DirectiveLocation.Object)) } -} \ No newline at end of file +}