sangria-ion

Sangria Amazon Ion marshalling

License

License

GroupId

GroupId

org.sangria-graphql
ArtifactId

ArtifactId

sangria-ion_2.11
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

sangria-ion
Sangria Amazon Ion marshalling
Project Organization

Project Organization

org.sangria-graphql
Source Code Management

Source Code Management

https://github.com/sangria-graphql-org/sangria-ion.git

Download sangria-ion_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/org.sangria-graphql/sangria-ion_2.11/ -->
<dependency>
    <groupId>org.sangria-graphql</groupId>
    <artifactId>sangria-ion_2.11</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.sangria-graphql/sangria-ion_2.11/
implementation 'org.sangria-graphql:sangria-ion_2.11:2.0.0'
// https://jarcasting.com/artifacts/org.sangria-graphql/sangria-ion_2.11/
implementation ("org.sangria-graphql:sangria-ion_2.11:2.0.0")
'org.sangria-graphql:sangria-ion_2.11:jar:2.0.0'
<dependency org="org.sangria-graphql" name="sangria-ion_2.11" rev="2.0.0">
  <artifact name="sangria-ion_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.sangria-graphql', module='sangria-ion_2.11', version='2.0.0')
)
libraryDependencies += "org.sangria-graphql" % "sangria-ion_2.11" % "2.0.0"
[org.sangria-graphql/sangria-ion_2.11 "2.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.sangria-graphql : sangria-marshalling-api_2.11 jar 1.0.4
software.amazon.ion : ion-java jar 1.5.1

test (2)

Group / Artifact Type Version
org.sangria-graphql : sangria-marshalling-testkit_2.11 jar 1.0.2
org.scalatest : scalatest_2.11 jar 3.0.8

Project Modules

There are no modules declared in this project.

Sangria Amazon Ion marshalling.

Build Status Coverage Status Maven Central License Join the chat at https://gitter.im/sangria-graphql/sangria

SBT Configuration:

libraryDependencies += "org.sangria-graphql" %% "sangria-ion" % "1.0.0"

Example

Here is small example of how you can use it, which also demonstrates custom scalar values that are natively supported by Ion.

First let's define the scalar values:

val dateFormat = new SimpleDateFormat("yyyy-MM-dd")

case object DateCoercionViolation extends ValueCoercionViolation("Date value expected")
case object BinaryCoercionViolation extends ValueCoercionViolation("Binary data is not supported as input")

def parseDate(s: String) = Try(dateFormat.parse(s)) match {
  case Success(d)  Right(d)
  case Failure(error)  Left(DateCoercionViolation)
}

val DateType = ScalarType[Date]("Date",
  coerceOutput = (d, caps) 
    if (caps.contains(DateSupport)) d
    else dateFormat.format(d),
  coerceUserInput = {
    case s: String  parseDate(s)
    case _  Left(DateCoercionViolation)
  },
  coerceInput = {
    case ast.StringValue(s, _)  parseDate(s)
    case _  Left(DateCoercionViolation)
  })

val BlobType = ScalarType[Array[Byte]]("Blob",
  coerceOutput = (d, _)  d,
  coerceUserInput = _  Left(BinaryCoercionViolation),
  coerceInput = _  Left(BinaryCoercionViolation))

val ClobType = ScalarType[Array[Byte]]("Clob",
  coerceOutput = (d, _)  d,
  coerceUserInput = _  Left(BinaryCoercionViolation),
  coerceInput = _  Left(BinaryCoercionViolation),
  scalarInfo = Set(IonClobScalar))

Please notice that Date type produces java.util.Date only when this capability is supported by the marshaller. Otherwise it produces a String alternative. Clob type also instructs marshaller to to use Ion clob type instead of blob for a byte array.

In order to use Ion marshalling, you also need an implicit instance of IonSystem in scope:

import sangria.marshalling.ion._

implicit val ionSystem = IonSystemBuilder.standard().build()

val result: Future[IonValue] = Executor.execute(schema, query)

Now you should be able to write IonValue to a binary or a text format.

License

sangria-ion is licensed under Apache License, Version 2.0.

org.sangria-graphql

Sangria

Sangria - Scala GraphQL implementation - temp fork not used anymore - see https://github.com/sangria-graphql/sangria/issues/446#issuecomment-546281588

Versions

Version
2.0.0
1.0.0
0.1.1
0.1.0