Skip to content

Proxied documents are no longer hardcoded to the "query" operation type. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

@OlegIlyenko OlegIlyenko Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can replace hardcoded ast.OperationType.Query with something like this:

c.query.operationType(c.ctx.operationName) getOrElse 
  throw new IllegalStateException(s"Can't find operation type")

You need to consider the operationName since it defines which operation must be executed if multiple operations are defined in the query.

Otherwise it looks good to me 👍 In future we need to think of a way how we can detach these 2. For example, in case I'm doing a mutation, but the delegate one of the nested fields. in this case delegated query type is Query even though original query is a Mutation

val query = ast.Document(queryOp +: fragments)

ctx.request(schema, query, c.ctx.queryVars, c.astFields.head.outputName).map(value ⇒
Expand Down Expand Up @@ -183,4 +184,4 @@ object GraphQLDirectiveProvider {
arguments = Args.Fields :: Nil,
locations = Set(DirectiveLocation.Object))
}
}
}