Skip to content
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

Unfortunate handling of query validation in subscriptions in sangria. #8

Open
ValdemarGr opened this issue Apr 21, 2022 · 1 comment

Comments

@ValdemarGr
Copy link

ValdemarGr commented Apr 21, 2022

Some query errors are only thrown on execution or preparation in sangria which causes the following code to fail in F instead of in Either[Throwable, Json] even though the error is in fact a graphql error.

fs2.Stream.eval {
Dispatcher[F].use { implicit d =>
Async[F].fromFuture {
Async[F].delay {
Executor.prepare(
schema = schema,
queryAst = request.query,
userContext = userData,
operationName = request.op,
variables = request.vars.getOrElse(Json.fromJsonObject(JsonObject())),
exceptionHandler = exceptionHandler
).map { preparedQuery =>
preparedQuery
.execute()
.map(_.asRight[Throwable])
.recover { case NonFatal(error) => error.asLeft[Json] }
}
}
}
}
} .flatten

An example of this is the following error:

Field 'field' conflict because they return conflicting types 'A!' and 'A'. Use different aliases on the fields to fetch both if this was intentional. (line n, column k):
    field
(line x, column y):
    field

When this occurs the subscription "hangs", no error or anything, which seems to be because a fiber is started but does not interact with the subscription in case of any error outcomes.

We have deployed the following fix:

    fs2.Stream.eval {
      Dispatcher[F].use { implicit d =>
        Async[F].fromFuture {
          Async[F].delay {
            Executor.prepare(
              schema           = schema,
              queryAst         = request.query,
              userContext      = userData,
              operationName    = request.op,
              variables        = request.vars.getOrElse(Json.fromJsonObject(JsonObject())),
              exceptionHandler = exceptionHandler
            ).map { preparedQuery =>
              preparedQuery
                .execute()
                .map(_.asRight[Throwable])
                .recover { case NonFatal(error) => error.asLeft[Json] }
            }
          }
        }
      }
    } .flatten
+ .attempt
+ .map(_.flatten)
@tpolecat
Copy link
Member

👍 Thanks for the report!

@ValdemarGr ValdemarGr changed the title Unfortunate handling og query validation in subscriptions in sangria. Unfortunate handling of query validation in subscriptions in sangria. Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants