Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private static List<EnumValueDefinition> map(List<graphql.language.EnumValueDefi
return enumValueDefinitions.stream()
.map(f -> new EnumValueDefinition(
MapperUtils.capitalizeIfRestricted(f.getName()),
f.getName(),
getJavaDoc(f.getComments()),
isDeprecated(f)))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class MapperUtils {

private static final Set<String> JAVA_RESTRICTED_KEYWORDS = new HashSet<>(Arrays.asList(
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
"default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if",
"implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package",
"default", "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto",
"if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package",
"private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
"synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static String mapEnum(MappingContext mappingContext, EnumValue value, Ty
if (graphQLType instanceof TypeName) {
String typeName = ((TypeName) graphQLType).getName();
typeName = MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, typeName);
return typeName + "." + value.getName();
return typeName + "." + MapperUtils.capitalizeIfRestricted(value.getName());
}
if (graphQLType instanceof NonNullType) {
return mapEnum(mappingContext, value, ((NonNullType) graphQLType).getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
*/
public class EnumValueDefinition {

private final String value;
private final String javaName;
private final String graphqlName;
private final List<String> javaDoc;
private final boolean deprecated;

public EnumValueDefinition(String value, List<String> javaDoc, boolean deprecated) {
this.value = value;
public EnumValueDefinition(String javaName, String graphqlName, List<String> javaDoc, boolean deprecated) {
this.javaName = javaName;
this.graphqlName = graphqlName;
this.javaDoc = javaDoc;
this.deprecated = deprecated;
}

public String getValue() {
return value;
public String getJavaName() {
return javaName;
}

public String getGraphqlName() {
return graphqlName;
}

public List<String> getJavaDoc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private static String getEntry(Object input, boolean jsonQuery) {
if (input == null) {
return null;
}
if (input instanceof Collection) {
Collection<?> inputCollection = (Collection) input;
if (input instanceof Collection<?>) {
Collection<?> inputCollection = (Collection<?>) input;
return inputCollection.stream()
.map(i -> GraphQLRequestSerializer.getEntry(i, jsonQuery))
.collect(Collectors.joining(", ", "[ ", " ]"));
Expand Down
13 changes: 12 additions & 1 deletion src/main/resources/templates/javaClassGraphqlEnum.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ public enum ${className}<#if implements?has_content> implements <#list implement
<#if field.deprecated>
@Deprecated
</#if>
${field.value}<#if field_has_next>,</#if>
${field.javaName}("${field.graphqlName}")<#if field_has_next>,<#else>;</#if>
</#list>
</#if>

private final String graphqlName;

private ${className}(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void generate() throws Exception {
"NativeQueryResponse.java", "PrivateQueryAPI.java", "PrivateQueryRequest.java",
"PrivateQueryResponse.java", "Query.java", "QueryAPI.java", "QueryCaseParametrizedInput.java",
"QueryPrivateParametrizedInput.java", "QueryResolver.java", "QueryResponseProjection.java",
"Synchronized.java", "SynchronizedResponseProjection.java"), generatedFileNames);
"Synchronized.java", "SynchronizedResponseProjection.java", "TestEnum.java"), generatedFileNames);

for (File file : files) {
assertSameTrimmedContent(
Expand Down
17 changes: 14 additions & 3 deletions src/test/resources/expected-classes/EventStatus.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ public enum EventStatus {
* OPEN status
* Means just created
*/
OPEN,
IN_PROGRESS,
OPEN("OPEN"),
IN_PROGRESS("IN_PROGRESS"),
/**
* Logging completed
*/
LOGGED
LOGGED("LOGGED");

private final String graphqlName;

private EventStatus(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
17 changes: 14 additions & 3 deletions src/test/resources/expected-classes/defaults/MyEnum.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ package com.kobylynskyi.graphql.testdefaults;
)
public enum MyEnum {

ONE,
TWO,
THREE
ONE("ONE"),
TWO("TWO"),
THREE("THREE");

private final String graphqlName;

private MyEnum(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
17 changes: 14 additions & 3 deletions src/test/resources/expected-classes/defaults/MyEnumTO.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ package com.kobylynskyi.graphql.testdefaults;
)
public enum MyEnumTO {

ONE,
TWO,
THREE
ONE("ONE"),
TWO("TWO"),
THREE("THREE");

private final String graphqlName;

private MyEnumTO(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
15 changes: 13 additions & 2 deletions src/test/resources/expected-classes/deprecated/Status.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ package com.kobylynskyi.graphql.test1;
public enum Status {

@Deprecated
CREATED,
IN_PROGRESS
CREATED("CREATED"),
IN_PROGRESS("IN_PROGRESS");

private final String graphqlName;

private Status(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
11 changes: 11 additions & 0 deletions src/test/resources/expected-classes/empty/Status.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
public enum Status {


private final String graphqlName;

private Status(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ package com.kobylynskyi.graphql.enumunion;
)
public enum EnumMember1 implements EnumUnion {

VALUE
VALUE("VALUE");

private final String graphqlName;

private EnumMember1(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ package com.kobylynskyi.graphql.enumunion;
)
public enum EnumMember2 implements EnumUnion {

OTHER_VALUE
OTHER_VALUE("OTHER_VALUE");

private final String graphqlName;

private EnumMember2(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
)
public enum Status {

CREATED,
IN_PROGRESS,
ASSIGNED
CREATED("CREATED"),
IN_PROGRESS("IN_PROGRESS"),
ASSIGNED("ASSIGNED");

private final String graphqlName;

private Status(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
17 changes: 14 additions & 3 deletions src/test/resources/expected-classes/extend/Status.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
)
public enum Status {

CREATED,
IN_PROGRESS,
ASSIGNED
CREATED("CREATED"),
IN_PROGRESS("IN_PROGRESS"),
ASSIGNED("ASSIGNED");

private final String graphqlName;

private Status(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
17 changes: 14 additions & 3 deletions src/test/resources/expected-classes/request/EventStatusTO.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ public enum EventStatusTO {
* OPEN status
* Means just created
*/
OPEN,
IN_PROGRESS,
OPEN("OPEN"),
IN_PROGRESS("IN_PROGRESS"),
/**
* Logging completed
*/
LOGGED
LOGGED("LOGGED");

private final String graphqlName;

private EventStatusTO(String graphqlName) {
this.graphqlName = graphqlName;
}

@Override
public String toString() {
return this.graphqlName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package com.kobylynskyi.graphql.codegen.prot;
)
public interface PrivateQueryAPI {

Synchronized Private(Integer Int, String New) throws Exception;
Synchronized Private(Integer Int, String New, TestEnum Enum) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class PrivateQueryRequest implements GraphQLOperationRequest {
this.input.put("new", New);
}

public void setEnum(TestEnum Enum) {
this.input.put("enum", Enum);
}

@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
Expand Down Expand Up @@ -70,6 +74,7 @@ public class PrivateQueryRequest implements GraphQLOperationRequest {

private Integer Int;
private String New;
private TestEnum Enum = TestEnum.Long;

public Builder() {
}
Expand All @@ -84,13 +89,19 @@ public class PrivateQueryRequest implements GraphQLOperationRequest {
return this;
}

public Builder setEnum(TestEnum Enum) {
this.Enum = Enum;
return this;
}


public PrivateQueryRequest build() {
PrivateQueryRequest obj = new PrivateQueryRequest();
obj.setInt(Int);
obj.setNew(New);
obj.setEnum(Enum);
return obj;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface QueryAPI {

String Native() throws Exception;

Synchronized Private(Integer Int, String New) throws Exception;
Synchronized Private(Integer Int, String New, TestEnum Enum) throws Exception;

String Case(java.util.List<Char> Final) throws Exception;

Expand Down
Loading