private NodePrinter<EnumValue> enumValue() { return (out, node) -> out.printf("%s", node.getName()); }
@Override public EnumValue deepCopy() { return new EnumValue(name, getSourceLocation(), getComments(), getIgnoredChars()); }
private Builder(EnumValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); }
return EnumValue.newEnumValue().name(stringValue).build();
public EnumValue build() { EnumValue enumValue = new EnumValue(name, sourceLocation, comments, ignoredChars); return enumValue; } }
private Builder(EnumValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); }
return stringValue.build(); } else if (ctx.enumValue() != null) { EnumValue.Builder enumValue = EnumValue.newEnumValue().name(ctx.enumValue().getText()); addCommonData(enumValue, ctx); return enumValue.build();
public EnumValue build() { EnumValue enumValue = new EnumValue(name, sourceLocation, comments, ignoredChars); return enumValue; } }
private void checkArgValueMatchesAllowedEnum(List<GraphQLError> errors, Value instanceValue, EnumTypeDefinition allowedTypeDefinition) { if (!(instanceValue instanceof EnumValue)) { addValidationError(errors, EXPECTED_ENUM_MESSAGE, instanceValue.getClass().getSimpleName()); return; } EnumValue enumValue = ((EnumValue) instanceValue); boolean noneMatchAllowedEnumValue = allowedTypeDefinition.getEnumValueDefinitions().stream() .noneMatch(enumAllowedValue -> enumAllowedValue.getName().equals(enumValue.getName())); if (noneMatchAllowedEnumValue) { addValidationError(errors, MUST_BE_VALID_ENUM_VALUE_MESSAGE, enumValue.getName(), allowedTypeDefinition.getEnumValueDefinitions().stream() .map(EnumValueDefinition::getName) .collect(Collectors.joining(","))); } }
@Override public EnumValue deepCopy() { return new EnumValue(name, getSourceLocation(), getComments(), getIgnoredChars()); }
return stringValue.build(); } else if (ctx.enumValue() != null) { EnumValue.Builder enumValue = EnumValue.newEnumValue().name(ctx.enumValue().getText()); addCommonData(enumValue, ctx); return enumValue.build();
@Override public Object parseLiteral(Object input) { if (!(input instanceof EnumValue)) { throw new CoercingParseLiteralException( "Expected AST type 'EnumValue' but was '" + typeName(input) + "'." ); } EnumValue enumValue = (EnumValue) input; GraphQLEnumValueDefinition enumValueDefinition = valueDefinitionMap.get(enumValue.getName()); if (enumValueDefinition == null) { throw new CoercingParseLiteralException( "Expected enum literal value not in allowable values - '" + String.valueOf(input) + "'." ); } return enumValueDefinition.getValue(); } };
return EnumValue.newEnumValue().name(stringValue).build();
public Object buildValue(Value value, GraphQLType requiredType) { Object result = null; if (GraphQLTypeUtil.isNonNull(requiredType)) { requiredType = unwrapOne(requiredType); } if (value == null) { return null; } if (requiredType instanceof GraphQLScalarType) { result = parseLiteral(value, (GraphQLScalarType) requiredType); } else if (value instanceof EnumValue && requiredType instanceof GraphQLEnumType) { result = ((EnumValue) value).getName(); } else if (value instanceof ArrayValue && isList(requiredType)) { ArrayValue arrayValue = (ArrayValue) value; GraphQLType wrappedType = unwrapOne(requiredType); result = arrayValue.getValues().stream() .map(item -> this.buildValue(item, wrappedType)).collect(Collectors.toList()); } else if (value instanceof ObjectValue && requiredType instanceof GraphQLInputObjectType) { result = buildObjectValue((ObjectValue) value, (GraphQLInputObjectType) requiredType); } else if (!(value instanceof NullValue)) { assertShouldNeverHappen( "cannot build value of %s from %s", requiredType.getName(), String.valueOf(value)); } return result; }
return stringValue.build(); } else if (ctx.enumValue() != null) { EnumValue.Builder enumValue = EnumValue.newEnumValue().name(ctx.enumValue().getText()); addCommonData(enumValue, ctx); return enumValue.build();
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
return stringValue.build(); } else if (ctx.enumValue() != null) { EnumValue.Builder enumValue = EnumValue.newEnumValue().name(ctx.enumValue().getText()); addCommonData(enumValue, ctx); return enumValue.build();
private NodePrinter<EnumValue> enumValue() { return (out, node) -> out.printf("%s", node.getName()); }
private void checkArgValueMatchesAllowedEnum(List<GraphQLError> errors, Value instanceValue, EnumTypeDefinition allowedTypeDefinition) { if (!(instanceValue instanceof EnumValue)) { addValidationError(errors, EXPECTED_ENUM_MESSAGE, instanceValue.getClass().getSimpleName()); return; } EnumValue enumValue = ((EnumValue) instanceValue); boolean noneMatchAllowedEnumValue = allowedTypeDefinition.getEnumValueDefinitions().stream() .noneMatch(enumAllowedValue -> enumAllowedValue.getName().equals(enumValue.getName())); if (noneMatchAllowedEnumValue) { addValidationError(errors, MUST_BE_VALID_ENUM_VALUE_MESSAGE, enumValue.getName(), allowedTypeDefinition.getEnumValueDefinitions().stream() .map(EnumValueDefinition::getName) .collect(Collectors.joining(","))); } }
@Override public Object parseLiteral(Object input) { if (!(input instanceof EnumValue)) { throw new CoercingParseLiteralException( "Expected AST type 'EnumValue' but was '" + typeName(input) + "'." ); } EnumValue enumValue = (EnumValue) input; GraphQLEnumValueDefinition enumValueDefinition = valueDefinitionMap.get(enumValue.getName()); if (enumValueDefinition == null) { throw new CoercingParseLiteralException( "Expected enum literal value not in allowable values - '" + String.valueOf(input) + "'." ); } return enumValueDefinition.getValue(); } };