Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent capitalization of field names #172

Merged
merged 2 commits into from
May 8, 2019
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 @@ -21,6 +21,7 @@ class InputFieldSpec(
val javaType: TypeName,
val context: CodeGenerationContext
) {
private val normalizedName = name.decapitalize().escapeJavaReservedWord()

fun writeValueCode(writerParam: CodeBlock, marshaller: CodeBlock): CodeBlock {
return when (type) {
Expand All @@ -38,7 +39,7 @@ class InputFieldSpec(
}.let {
if (javaType.isOptional()) {
CodeBlock.builder()
.beginControlFlow("if (\$L.defined)", name)
.beginControlFlow("if (\$L.defined)", normalizedName)
.add(it)
.endControlFlow()
.build()
Expand All @@ -49,12 +50,12 @@ class InputFieldSpec(
}

private fun writeScalarCode(writerParam: CodeBlock): CodeBlock {
val valueCode = javaType.unwrapOptionalValue(varName = name, checkIfPresent = false)
val valueCode = javaType.unwrapOptionalValue(varName = normalizedName, checkIfPresent = false)
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
}

private fun writeEnumCode(writerParam: CodeBlock): CodeBlock {
val valueCode = javaType.unwrapOptionalValue(name) {
val valueCode = javaType.unwrapOptionalValue(normalizedName) {
CodeBlock.of("\$L.name()", it)
}
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
Expand All @@ -63,13 +64,13 @@ class InputFieldSpec(
private fun writeCustomCode(writerParam: CodeBlock): CodeBlock {
val customScalarEnum = CustomEnumTypeSpecBuilder.className(context)
val customScalarEnumConst = normalizeGraphQlType(graphQLType).toUpperCase(Locale.ENGLISH)
val valueCode = javaType.unwrapOptionalValue(name)
val valueCode = javaType.unwrapOptionalValue(normalizedName)
return CodeBlock.of("\$L.\$L(\$S, \$L.\$L, \$L);\n", writerParam, WRITE_METHODS[type],
name, customScalarEnum, customScalarEnumConst, valueCode)
}

private fun writeObjectCode(writerParam: CodeBlock, marshaller: CodeBlock): CodeBlock {
val valueCode = javaType.unwrapOptionalValue(name) {
val valueCode = javaType.unwrapOptionalValue(normalizedName) {
CodeBlock.of("\$L.\$L", it, marshaller)
}
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
Expand All @@ -80,7 +81,7 @@ class InputFieldSpec(
val writeMethod = SCALAR_LIST_ITEM_WRITE_METHODS[rawFieldType] ?: "writeString"
val writeStatement = CodeBlock.builder()
.beginControlFlow("for (\$T \$L : \$L)", rawFieldType, "\$item",
javaType.unwrapOptionalValue(name, false))
javaType.unwrapOptionalValue(normalizedName, false))
.add(
if (rawFieldType.isEnum(context)) {
CodeBlock.of("\$L.\$L(\$L.name());\n", LIST_ITEM_WRITER_PARAM.name, writeMethod, "\$item")
Expand All @@ -100,7 +101,7 @@ class InputFieldSpec(
.build()
)
.build()
val valueCode = javaType.unwrapOptionalValue(name) {
val valueCode = javaType.unwrapOptionalValue(normalizedName) {
CodeBlock.of("\$L", listWriterType)
}
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
Expand All @@ -112,7 +113,7 @@ class InputFieldSpec(
val customScalarEnumConst = normalizeGraphQlType(graphQLType).toUpperCase(Locale.ENGLISH)
val writeStatement = CodeBlock.builder()
.beginControlFlow("for (\$T \$L : \$L)", rawFieldType, "\$item",
javaType.unwrapOptionalValue(name, false))
javaType.unwrapOptionalValue(normalizedName, false))
.addStatement("\$L.writeCustom(\$T.\$L, \$L)", LIST_ITEM_WRITER_PARAM.name, customScalarEnum,
customScalarEnumConst, "\$item")
.endControlFlow()
Expand All @@ -128,7 +129,7 @@ class InputFieldSpec(
.build()
)
.build()
val valueCode = javaType.unwrapOptionalValue(name) {
val valueCode = javaType.unwrapOptionalValue(normalizedName) {
CodeBlock.of("\$L", listWriterType)
}
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
Expand All @@ -138,7 +139,7 @@ class InputFieldSpec(
val rawFieldType = with(javaType.unwrapOptionalType(true)) { if (isList()) listParamType() else this }
val writeStatement = CodeBlock.builder()
.beginControlFlow("for (\$T \$L : \$L)", rawFieldType, "\$item",
javaType.unwrapOptionalValue(name, false))
javaType.unwrapOptionalValue(normalizedName, false))
.addStatement("\$L.writeObject(\$L.\$L)", LIST_ITEM_WRITER_PARAM.name, "\$item", marshaller)
.endControlFlow()
.build()
Expand All @@ -153,7 +154,7 @@ class InputFieldSpec(
.build()
)
.build()
val valueCode = javaType.unwrapOptionalValue(name) {
val valueCode = javaType.unwrapOptionalValue(normalizedName) {
CodeBlock.of("\$L", listWriterType)
}
return CodeBlock.of("\$L.\$L(\$S, \$L);\n", writerParam, WRITE_METHODS[type], name, valueCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class InputTypeSpecBuilder(
val writeCode = fields
.map {
InputFieldSpec.build(
name = it.name.decapitalize(),
name = it.name,
graphQLType = it.type,
context = context
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public void onFailure(@Nonnull ApolloException e) {
public void testCache() {
AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM();
assertNotNull(awsAppSyncClient);
String postID = "bae84e6f-3c65-4c52-a68e-b7d32c6fa8ff";
String postID = "89511826-4414-4569-8d5d-075e9f12a923";

queryPost(awsAppSyncClient, AppSyncResponseFetchers.NETWORK_ONLY,postID);
assertNotNull(getPostQueryResponse);
Expand All @@ -669,7 +669,7 @@ public void testCache() {
public void testCacheWithInputType() {
AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM();
assertNotNull(awsAppSyncClient);
String postID = "bae84e6f-3c65-4c52-a68e-b7d32c6fa8ff";
String postID = "89511826-4414-4569-8d5d-075e9f12a923";
String name = "Home [Scene Six]";
int version = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@
"description" : null,
"fields" : null,
"inputFields" : [ {
"name" : "id",
"name" : "Id",
"description" : null,
"type" : {
"kind" : "NON_NULL",
Expand Down