本文整理汇总了Java中graphql.language.StringValue类的典型用法代码示例。如果您正苦于以下问题:Java StringValue类的具体用法?Java StringValue怎么用?Java StringValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringValue类属于graphql.language包,在下文中一共展示了StringValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Override
public ZonedDateTime parseLiteral(Object input) {
if (input instanceof StringValue) {
return ZonedDateTime.parse(((StringValue) input).getValue());
} else if (input instanceof IntValue) {
return Instant.ofEpochMilli(((IntValue) input).getValue().longValue()).atZone(ZoneOffset.UTC);
} else {
return null;
}
}
示例2: getInstant
import graphql.language.StringValue; //导入依赖的package包/类
private Instant getInstant(Object input) {
if (input instanceof Instant) {
return (Instant) input;
} else if (input instanceof String) {
return Instant.parse((String) input);
} else if (input instanceof StringValue) {
return Instant.parse(((StringValue) input).getValue());
}
return null;
}
示例3: getDuration
import graphql.language.StringValue; //导入依赖的package包/类
private Duration getDuration(Object input) {
if (input instanceof Duration) {
return (Duration) input;
} else if (input instanceof String) {
return Duration.parse((String) input);
} else if (input instanceof StringValue) {
return Duration.parse(((StringValue) input).getValue());
}
return null;
}
示例4: instant_Serialize_StringValue
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void instant_Serialize_StringValue() {
// Given
val input = new StringValue("2016-11-21T06:00:00Z");
// When
val parseResult = Scalars.GraphQlInstant.getCoercing().serialize(input);
// Then
assertThat(parseResult).isEqualTo(LocalDateTime.of(2016, 11, 21, 6, 0).toInstant(ZoneOffset.UTC));
}
示例5: instant_ParseLiteral_WrongStringInput_ShouldThrowDateTimeParseException
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void instant_ParseLiteral_WrongStringInput_ShouldThrowDateTimeParseException() {
// Given
val input = new StringValue("2016-11-21T06:00:");
// When
val parseExcpetion = assertThatThrownBy(() -> Scalars.GraphQlInstant.getCoercing().parseLiteral(input));
// Then
parseExcpetion.isExactlyInstanceOf(DateTimeParseException.class).hasMessage("Text '2016-11-21T06:00:' could not be parsed at index 17");
}
示例6: duration_Serialize_StringValue
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void duration_Serialize_StringValue() {
// Given
val input = new StringValue("PT48H");
// When
val parseResult = Scalars.GraphQlDuration.getCoercing().serialize(input);
// Then
assertThat(parseResult).isEqualTo(Duration.ofHours(48));
}
示例7: duration_ParseLiteral_WrongStringInput_ShouldThrowDateTimeException
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void duration_ParseLiteral_WrongStringInput_ShouldThrowDateTimeException() {
// Given
val input = new StringValue("P48H");
// When
val parseExcpetion = assertThatThrownBy(() -> Scalars.GraphQlDuration.getCoercing().parseLiteral(input));
// Then
parseExcpetion.isExactlyInstanceOf(DateTimeParseException.class).hasMessage("Text cannot be parsed to a Duration");
}
示例8: testStringTemporal
import graphql.language.StringValue; //导入依赖的package包/类
private void testStringTemporal(Class type, Coercing coercing, String expected) {
Object parsed = coercing.parseLiteral(new StringValue(expected));
assertTrue(type.isInstance(parsed));
assertEquals(expected, coercing.serialize(parsed));
parsed = coercing.parseValue(expected);
assertTrue(type.isInstance(parsed));
assertEquals(expected, coercing.serialize(parsed));
Object same = coercing.parseValue(parsed);
assertEquals(parsed, same);
}
示例9: parseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Override
public Date parseLiteral(Object o) {
Object input;
if (o instanceof IntValue) {
input = ((IntValue) o).getValue().longValue();
} else if (o instanceof StringValue) {
input = ((StringValue) o).getValue();
} else {
throw new CoercingParseValueException(ERROR_BAD_EPOCH_TYPE);
}
return parseValue(input);
}
示例10: parseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Override
public Object parseLiteral(Object input) {
if (input instanceof StringValue) {
return parseStringToLocalDateTime(((StringValue) input).getValue());
} else if (input instanceof IntValue) {
BigInteger value = ((IntValue) input).getValue();
return parseLongToLocalDateTime(value.longValue());
}
return null;
}
示例11: getDirectiveArgument
import graphql.language.StringValue; //导入依赖的package包/类
public Optional<String> getDirectiveArgument(GraphQLObjectType parentType, String directiveName,
String argumentName) {
return Optional.ofNullable(parentType.getDefinition().getDirective(directiveName))
.map(d -> d.getArgument(argumentName))
.map(v -> (StringValue) v.getValue())
.map(StringValue::getValue);
}
示例12: parseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Override
public Object parseLiteral(Object input) {
if (!(input instanceof StringValue)) return null;
return UUID.fromString(((StringValue) input).getValue());
}
示例13: parseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Override
public Object parseLiteral(Object input) {
if (!(input instanceof StringValue)) return null;
return new Date(Long.parseLong(((StringValue) input).getValue()));
}
示例14: testGraphQLDateParseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void testGraphQLDateParseLiteral() {
Date date = new Date(123L);
assertEquals(GraphQLScalars.GRAPHQL_DATE_TYPE.getCoercing().parseLiteral(new StringValue("123")), date);
assertEquals(GraphQLScalars.GRAPHQL_DATE_TYPE.getCoercing().parseLiteral(new IntValue(new BigInteger("123"))), date);
}
示例15: testGraphQLDeferredIdParseLiteral
import graphql.language.StringValue; //导入依赖的package包/类
@Test
public void testGraphQLDeferredIdParseLiteral() {
assertEquals(GraphQLScalars.GRAPHQL_DEFERRED_ID.getCoercing().parseLiteral(new IntValue(new BigInteger("123"))), "123");
assertEquals(GraphQLScalars.GRAPHQL_DEFERRED_ID.getCoercing().parseLiteral(new StringValue("123")), "123");
}