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
5 changes: 4 additions & 1 deletion src/main/java/graphql/schema/PropertyFetchingImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import graphql.GraphQLException;
import graphql.Internal;
import graphql.schema.fetching.LambdaFetchingSupport;
import graphql.util.EscapeUtil;
import graphql.util.StringKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,6 +14,7 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -213,7 +216,7 @@ private Object getPropertyViaGetterMethod(Object object, String propertyName, Gr
}

private Object getPropertyViaGetterUsingPrefix(Object object, String propertyName, String prefix, MethodFinder methodFinder, Supplier<Object> singleArgumentValue) throws NoSuchMethodException {
String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
String getterName = prefix + StringKit.capitalize(propertyName);
Method method = methodFinder.apply(object.getClass(), getterName);
return invokeMethod(object, singleArgumentValue, method, takesSingleArgumentTypeAsOnlyArgument(method));
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/graphql/schema/diff/SchemaDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static graphql.language.TypeKind.getTypeKind;
import static graphql.schema.idl.TypeInfo.getAstDesc;
import static graphql.schema.idl.TypeInfo.typeInfo;
import static graphql.util.StringKit.capitalize;

/**
* The SchemaDiff is called with a {@link DiffSet} and will report the
Expand Down Expand Up @@ -974,15 +975,6 @@ private <T> Map<String, T> sortedMap(List<T> listOfNamedThings, Function<T, Stri
return new TreeMap<>(map);
}

private static String capitalize(String name) {
if (name != null && name.length() != 0) {
char[] chars = name.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
} else {
return name;
}
}

private String mkDotName(String... objectNames) {
return String.join(".", objectNames);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/graphql/util/StringKit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package graphql.util;

import java.util.Locale;

public class StringKit {

public static String capitalize(String s) {
if (s != null && !s.isEmpty()) {
StringBuilder sb = new StringBuilder();
// see https://github.com/graphql-java/graphql-java/issues/3385
sb.append(s.substring(0, 1).toUpperCase(Locale.ROOT));
if (s.length() > 1) {
sb.append(s.substring(1));
}
return sb.toString();
}
return s;
}

}
32 changes: 32 additions & 0 deletions src/test/groovy/graphql/schema/PropertyDataFetcherTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,38 @@ class PropertyDataFetcherTest extends Specification {
result == "bar"
}

class BaseObject {
private String id

String getId() {
return id
}

void setId(String value) {
id = value;
}
}

class OtherObject extends BaseObject {}

def "Can access private property from base class that starts with i in Turkish"() {
// see https://github.com/graphql-java/graphql-java/issues/3385
given:
Locale oldLocale = Locale.getDefault()
Locale.setDefault(new Locale("tr", "TR"))

def environment = env(new OtherObject(id: "aValue"))
def fetcher = PropertyDataFetcher.fetching("id")

when:
String propValue = fetcher.get(environment)

then:
propValue == 'aValue'

cleanup:
Locale.setDefault(oldLocale)
}
/**
* Classes from issue to ensure we reproduce as reported by customers
*
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/graphql/util/StringKitTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package graphql.util

import spock.lang.Specification

class StringKitTest extends Specification {


def "can capitalise"() {
expect:

def actual = StringKit.capitalize(input)
actual == expected

where:
input | expected
null | null
"" | ""
"a" | "A"
"abc" | "Abc"

}
}