graphql.schema.Coercing Java Examples

The following examples show how to use graphql.schema.Coercing. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractScalar.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
public AbstractScalar(String name,
        Coercing coercing,
        Class... supportedTypes) {

    super(name, "Scalar for " + name, coercing);
    this.supportedTypes = Arrays.asList(supportedTypes);

}
 
Example #2
Source File: Scalars.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
private static GraphQLScalarType scalar(String name, Coercing<?, ?> coercing) {
  return GraphQLScalarType
      .newScalar()
      .name(name)
      .description(name + " Scalar")
      .coercing(coercing)
      .build();
}
 
Example #3
Source File: TemporalScalarsTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSqlTypesAsDates() {
    Coercing dateCoercing = Scalars.toGraphQLScalarType(Date.class).getCoercing();
    Coercing sqlDateCoercing = Scalars.toGraphQLScalarType(java.sql.Date.class).getCoercing();
    Coercing sqlTimeCoercing = Scalars.toGraphQLScalarType(Time.class).getCoercing();
    Coercing sqlTimestampCoercing = Scalars.toGraphQLScalarType(Timestamp.class).getCoercing();
    java.sql.Date sqlDate = java.sql.Date.valueOf(LocalDate.parse("2017-06-24"));
    Time sqlTime = Time.valueOf(LocalTime.parse("23:15:44"));
    Timestamp sqlTimestamp = Timestamp.valueOf(LocalDateTime.parse("2017-06-24T23:15:44.500"));
    assertEquals(dateCoercing.serialize(sqlDate), sqlDateCoercing.serialize(sqlDate));
    assertEquals(dateCoercing.serialize(sqlTime), sqlTimeCoercing.serialize(sqlTime));
    assertEquals(dateCoercing.serialize(sqlTimestamp), sqlTimestampCoercing.serialize(sqlTimestamp));
}
 
Example #4
Source File: TemporalScalarsTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private void testStringTemporal(Class type, Coercing coercing, String expected, String stringLiteral) {
    Object parsed = coercing.parseLiteral(new StringValue(stringLiteral));
    assertTrue(type.isInstance(parsed));
    assertEquals(expected, coercing.serialize(parsed));

    parsed = coercing.parseValue(stringLiteral);
    assertTrue(type.isInstance(parsed));
    assertEquals(expected, coercing.serialize(parsed));
    
    Object same = coercing.parseValue(parsed);
    assertEquals(parsed, same);
}
 
Example #5
Source File: TemporalScalarsTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private void testEpochMilliTemporal(Class type, Coercing coercing, String expected, long literal) {
    Object parsed = coercing.parseLiteral(new IntValue(new BigInteger(Long.toString(literal))));
    assertTrue(type.isInstance(parsed));
    assertEquals(expected, coercing.serialize(parsed));
    
    parsed = coercing.parseValue(literal);
    assertTrue(type.isInstance(parsed));
    assertEquals(expected, coercing.serialize(parsed));
}
 
Example #6
Source File: _Any.java    From federation-jvm with MIT License 4 votes vote down vote up
static GraphQLScalarType type(Coercing coercing) {
    return newScalar()
            .name(typeName)
            .coercing(coercing)
            .build();
}
 
Example #7
Source File: SchemaTransformer.java    From federation-jvm with MIT License 4 votes vote down vote up
public SchemaTransformer coercingForAny(Coercing coercing) {
    this.coercingForAny = coercing;
    return this;
}