-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15306a5
commit 6fa249b
Showing
13 changed files
with
480 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
package caliban | ||
|
||
import caliban.CalibanError.{ ExecutionError, ParsingError, ValidationError } | ||
import caliban.ResponseValue.ObjectValue | ||
import caliban.interop.circe._ | ||
|
||
/** | ||
* Represents the result of a GraphQL query, containing a data object and a list of errors. | ||
*/ | ||
case class GraphQLResponse[+E](data: ResponseValue, errors: List[E]) | ||
case class GraphQLResponse[+E](data: ResponseValue, errors: List[E], extensions: Option[ObjectValue] = None) | ||
|
||
object GraphQLResponse { | ||
implicit def circeEncoder[F[_]: IsCirceEncoder, E]: F[GraphQLResponse[E]] = | ||
GraphQLResponceCirce.graphQLResponseEncoder.asInstanceOf[F[GraphQLResponse[E]]] | ||
GraphQLResponseCirce.graphQLResponseEncoder.asInstanceOf[F[GraphQLResponse[E]]] | ||
} | ||
|
||
private object GraphQLResponceCirce { | ||
private object GraphQLResponseCirce { | ||
import io.circe._ | ||
import io.circe.syntax._ | ||
val graphQLResponseEncoder: Encoder[GraphQLResponse[CalibanError]] = Encoder | ||
.instance[GraphQLResponse[CalibanError]] { | ||
case GraphQLResponse(data, Nil) => Json.obj("data" -> data.asJson) | ||
case GraphQLResponse(data, errors) => | ||
case GraphQLResponse(data, Nil, None) => Json.obj("data" -> data.asJson) | ||
case GraphQLResponse(data, Nil, Some(extensions)) => | ||
Json.obj("data" -> data.asJson, "extensions" -> extensions.asInstanceOf[ResponseValue].asJson) | ||
case GraphQLResponse(data, errors, None) => | ||
Json.obj("data" -> data.asJson, "errors" -> Json.fromValues(errors.map(handleError))) | ||
case GraphQLResponse(data, errors, Some(extensions)) => | ||
Json.obj( | ||
"data" -> data.asJson, | ||
"errors" -> Json.fromValues(errors.map(err => Json.obj("message" -> Json.fromString(err.toString)))) | ||
"data" -> data.asJson, | ||
"errors" -> Json.fromValues(errors.map(handleError)), | ||
"extensions" -> extensions.asInstanceOf[ResponseValue].asJson | ||
) | ||
} | ||
|
||
private def handleError(err: CalibanError): Json = | ||
err match { | ||
case _: ParsingError | _: ValidationError => Json.obj("message" -> Json.fromString(err.toString)) | ||
case ExecutionError(_, _, path, _) => | ||
Json.obj( | ||
"message" -> Json.fromString(err.toString), | ||
"path" -> Json.fromValues(path.map { | ||
case Left(value) => Json.fromString(value) | ||
case Right(value) => Json.fromInt(value) | ||
}) | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package caliban.execution | ||
|
||
case class FieldInfo(fieldName: String, path: List[Either[String, Int]], parentType: String, returnType: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.