use of com.graphql_java_generator.plugin.language.EnumValue in project graphql-maven-plugin-project by graphql-java-generator.
the class DocumentParser method readEnumType.
/**
* Reads an enum definition, and create the relevant {@link EnumType}
*
* @param node
* @return
*/
public EnumType readEnumType(EnumTypeDefinition node) {
EnumType enumType = new EnumType(node.getName(), configuration, this);
enumType.setAppliedDirectives(readAppliedDirectives(node.getDirectives()));
// Let's store its comments
enumType.setComments(node.getComments());
for (EnumValueDefinition enumValDef : node.getEnumValueDefinitions()) {
EnumValue val = EnumValueImpl.builder().name(enumValDef.getName()).appliedDirectives(readAppliedDirectives(enumValDef.getDirectives())).build();
enumType.getValues().add(val);
}
return enumType;
}
use of com.graphql_java_generator.plugin.language.EnumValue in project graphql-maven-plugin-project by graphql-java-generator.
the class DocumentParser_allGraphQLCases_Server_Test method checkDirectivesOnEnumValue.
/**
* Check that a Directive for an object, field, scalar (...) has been properly parsed
*
* @param type
* @param enumValueName
* The name of the field, within the given type
* @param containsTestDirective
* true if this type contains the testDirective
* @param value
* Value of the 'value' field of the testDirective
* @param anotherValue
* Value of the 'anotherValue' field of the testDirective
* @param containsAnotherTestDirective
* true if this type contains the anotherTestDirective
*/
private void checkDirectivesOnEnumValue(Type type, String enumValueName, boolean containsTestDirective, String value, String anotherValue, boolean containsAnotherTestDirective) {
EnumValue enumValue = null;
for (EnumValue f : ((EnumType) type).getValues()) {
if (f.getName().equals(enumValueName)) {
enumValue = f;
break;
}
}
if (enumValue == null) {
fail("Could not find the enum value '" + enumValueName + "' on enum '" + type.getName() + "'");
}
int nbDirectives = (containsTestDirective ? 1 : 0) + (containsAnotherTestDirective ? 1 : 0);
assertEquals(nbDirectives, enumValue.getAppliedDirectives().size());
if (containsTestDirective) {
assertEquals("testDirective", enumValue.getAppliedDirectives().get(0).getDirective().getName());
// check arguments
assertEquals(value, ((StringValue) enumValue.getAppliedDirectives().get(0).getArgumentValues().get("value")).getValue());
if (anotherValue != null)
assertEquals(anotherValue, ((StringValue) enumValue.getAppliedDirectives().get(0).getArgumentValues().get("anotherValue")).getValue());
}
if (containsAnotherTestDirective) {
int index = containsTestDirective ? 1 : 0;
assertEquals("anotherTestDirective", enumValue.getAppliedDirectives().get(index).getDirective().getName());
}
}
Aggregations