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 useJavaBeansSemanticNaming and boolean field starts with is #881

Merged
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 @@ -16,6 +16,9 @@ fun String.escapeJavaReservedWord() = if (JAVA_RESERVED_WORDS.contains(this)) "$

fun String.toJavaBeansSemanticNaming(isBooleanField: Boolean): String {
val prefix = if (isBooleanField) "is" else "get"
if (isBooleanField && startsWith(prefix) && removePrefix(prefix) == removePrefix(prefix).capitalize()) {
return this
}
return "$prefix${capitalize()}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fragment HeroDetails on Character {
pageInfo {
hasNextPage
}
isEmpty
}
... on Droid {
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"fragmentsReferenced": [
"HeroDetails"
],
"sourceWithFragments": "query TestQuery {\n hero {\n __typename\n name\n ...HeroDetails\n appearsIn\n }\n}\nfragment HeroDetails on Character {\n __typename\n name\n friendsConnection {\n __typename\n totalCount\n edges {\n __typename\n node {\n __typename\n name\n }\n }\n pageInfo {\n __typename\n hasNextPage\n }\n }\n ... on Droid {\n name\n primaryFunction\n }\n}",
"operationId": "c0463bc20566eabd263da887f6c45205c7b42522fa28585baf0e9f6021a2a8a6"
"sourceWithFragments": "query TestQuery {\n hero {\n __typename\n name\n ...HeroDetails\n appearsIn\n }\n}\nfragment HeroDetails on Character {\n __typename\n name\n friendsConnection {\n __typename\n totalCount\n edges {\n __typename\n node {\n __typename\n name\n }\n }\n pageInfo {\n __typename\n hasNextPage\n }\n isEmpty\n }\n ... on Droid {\n name\n primaryFunction\n }\n}",
"operationId": "4141e194c5f3846dabfcb576e735c71968b03a940baf49cc5e647c5e50eda72a"
}
],
"fragments": [
Expand All @@ -65,7 +65,7 @@
],
"fragmentName": "HeroDetails",
"filePath": "src/test/graphql/com/example/java_beans_semantic_naming/TestOperation.graphql",
"source": "fragment HeroDetails on Character {\n __typename\n name\n friendsConnection {\n __typename\n totalCount\n edges {\n __typename\n node {\n __typename\n name\n }\n }\n pageInfo {\n __typename\n hasNextPage\n }\n }\n ... on Droid {\n name\n primaryFunction\n }\n}",
"source": "fragment HeroDetails on Character {\n __typename\n name\n friendsConnection {\n __typename\n totalCount\n edges {\n __typename\n node {\n __typename\n name\n }\n }\n pageInfo {\n __typename\n hasNextPage\n }\n isEmpty\n }\n ... on Droid {\n name\n primaryFunction\n }\n}",
"fields": [
{
"responseName": "__typename",
Expand Down Expand Up @@ -179,6 +179,15 @@
],
"fragmentSpreads": [],
"inlineFragments": []
},
{
"responseName": "isEmpty",
"fieldName": "isEmpty",
"type": "Boolean!",
"isConditional": false,
"description": "For test java beans semantic naming only",
"isDeprecated": false,
"deprecationReason": null
}
],
"fragmentSpreads": [],
Expand Down Expand Up @@ -305,6 +314,15 @@
],
"fragmentSpreads": [],
"inlineFragments": []
},
{
"responseName": "isEmpty",
"fieldName": "isEmpty",
"type": "Boolean!",
"isConditional": false,
"description": "For test java beans semantic naming only",
"isDeprecated": false,
"deprecationReason": null
}
],
"fragmentSpreads": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class TestQuery implements Query<TestQuery.Data, Optional<TestQuery
+ " }\n"
+ "}";

public static final String OPERATION_ID = "c0463bc20566eabd263da887f6c45205c7b42522fa28585baf0e9f6021a2a8a6";
public static final String OPERATION_ID = "4141e194c5f3846dabfcb576e735c71968b03a940baf49cc5e647c5e50eda72a";

public static final String QUERY_DOCUMENT = OPERATION_DEFINITION + "\n"
+ HeroDetails.FRAGMENT_DEFINITION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public interface HeroDetails extends GraphqlFragment {
+ " __typename\n"
+ " hasNextPage\n"
+ " }\n"
+ " isEmpty\n"
+ " }\n"
+ " ... on Droid {\n"
+ " name\n"
Expand Down Expand Up @@ -97,6 +98,11 @@ interface FriendsConnection {
*/
@Nonnull PageInfo getPageInfo();

/**
* For test java beans semantic naming only
*/
boolean isEmpty();

ResponseFieldMarshaller marshaller();
}

Expand Down Expand Up @@ -267,7 +273,8 @@ class FriendsConnection1 implements FriendsConnection {
ResponseField.forString("__typename", "__typename", null, false, Collections.<ResponseField.Condition>emptyList()),
ResponseField.forLong("totalCount", "totalCount", null, true, Collections.<ResponseField.Condition>emptyList()),
ResponseField.forList("edges", "edges", null, true, Collections.<ResponseField.Condition>emptyList()),
ResponseField.forObject("pageInfo", "pageInfo", null, false, Collections.<ResponseField.Condition>emptyList())
ResponseField.forObject("pageInfo", "pageInfo", null, false, Collections.<ResponseField.Condition>emptyList()),
ResponseField.forBoolean("isEmpty", "isEmpty", null, false, Collections.<ResponseField.Condition>emptyList())
};

final @Nonnull String __typename;
Expand All @@ -278,18 +285,21 @@ class FriendsConnection1 implements FriendsConnection {

final @Nonnull PageInfo1 pageInfo;

final boolean isEmpty;

private volatile String $toString;

private volatile int $hashCode;

private volatile boolean $hashCodeMemoized;

public FriendsConnection1(@Nonnull String __typename, @Nullable Long totalCount,
@Nullable List<Edge1> edges, @Nonnull PageInfo1 pageInfo) {
@Nullable List<Edge1> edges, @Nonnull PageInfo1 pageInfo, boolean isEmpty) {
this.__typename = Utils.checkNotNull(__typename, "__typename == null");
this.totalCount = Optional.fromNullable(totalCount);
this.edges = Optional.fromNullable(edges);
this.pageInfo = Utils.checkNotNull(pageInfo, "pageInfo == null");
this.isEmpty = isEmpty;
}

public @Nonnull String get__typename() {
Expand Down Expand Up @@ -317,6 +327,13 @@ public Optional<List<Edge1>> getEdges() {
return this.pageInfo;
}

/**
* For test java beans semantic naming only
*/
public boolean isEmpty() {
return this.isEmpty;
}

public ResponseFieldMarshaller marshaller() {
return new ResponseFieldMarshaller() {
@Override
Expand All @@ -330,6 +347,7 @@ public void write(Object value, ResponseWriter.ListItemWriter listItemWriter) {
}
});
writer.writeObject($responseFields[3], pageInfo.marshaller());
writer.writeBoolean($responseFields[4], isEmpty);
}
};
}
Expand All @@ -341,7 +359,8 @@ public String toString() {
+ "__typename=" + __typename + ", "
+ "totalCount=" + totalCount + ", "
+ "edges=" + edges + ", "
+ "pageInfo=" + pageInfo
+ "pageInfo=" + pageInfo + ", "
+ "isEmpty=" + isEmpty
+ "}";
}
return $toString;
Expand All @@ -357,7 +376,8 @@ public boolean equals(Object o) {
return this.__typename.equals(that.__typename)
&& this.totalCount.equals(that.totalCount)
&& this.edges.equals(that.edges)
&& this.pageInfo.equals(that.pageInfo);
&& this.pageInfo.equals(that.pageInfo)
&& this.isEmpty == that.isEmpty;
}
return false;
}
Expand All @@ -374,6 +394,8 @@ public int hashCode() {
h ^= edges.hashCode();
h *= 1000003;
h ^= pageInfo.hashCode();
h *= 1000003;
h ^= Boolean.valueOf(isEmpty).hashCode();
$hashCode = h;
$hashCodeMemoized = true;
}
Expand Down Expand Up @@ -406,7 +428,8 @@ public PageInfo1 read(ResponseReader reader) {
return pageInfo1FieldMapper.map(reader);
}
});
return new FriendsConnection1(__typename, totalCount, edges, pageInfo);
final boolean isEmpty = reader.readBoolean($responseFields[4]);
return new FriendsConnection1(__typename, totalCount, edges, pageInfo, isEmpty);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions apollo-compiler/src/test/graphql/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,22 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "isEmpty",
"description": "For test java beans semantic naming only",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down