这是indexloc提供的服务,不要输入任何密码
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
4 changes: 4 additions & 0 deletions support/src/main/java/com/shopify/graphql/support/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
public abstract class Query<T extends Query> {
public static final String ALIAS_SUFFIX_SEPARATOR = "__";
private static final String BAD_ALIAS_SEPARATOR = "-";
private static final String ALIAS_DELIMITER = ":";
protected final StringBuilder _queryBuilder;
private boolean firstSelection = true;
Expand Down Expand Up @@ -82,6 +83,9 @@ public T withAlias(String aliasSuffix) {
if (aliasSuffix.contains(Query.ALIAS_SUFFIX_SEPARATOR)) {
throw new IllegalArgumentException("Alias must not contain __");
}
if (aliasSuffix.contains(Query.BAD_ALIAS_SEPARATOR)) {
throw new IllegalArgumentException("Alias must not contain -");
}
this.aliasSuffix = aliasSuffix;
// noinspection unchecked
return (T) this;
Expand Down
32 changes: 10 additions & 22 deletions support/src/test/java/com/shopify/graphql/support/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class QueryTest {
@Test
Expand All @@ -13,29 +12,18 @@ public void testStringEscaping() throws Exception {
assertEquals("\"\\u0000 \\r \\n \\\\ \\\" c ꝏ\"", result.toString());
}

@Test
public void testInvalidAlias() {
boolean exceptionThrown = false;
try {
new Query<Query>(null) {
}.withAlias("invalid__alias");
} catch (IllegalArgumentException e) {
exceptionThrown = true;
} finally {
assertTrue(exceptionThrown);
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidAliasWithUnderscore() {
new Query<Query>(null) {}.withAlias("invalid__alias");
}

@Test
@Test(expected = IllegalArgumentException.class)
public void testInvalidAliasWithDashes() {
new Query<Query>(null) {}.withAlias("invalid-alias");
}

@Test(expected = IllegalArgumentException.class)
public void testBlankAlias() {
boolean exceptionThrown = false;
try {
new Query<Query>(null) {
}.withAlias("");
} catch (IllegalArgumentException e) {
exceptionThrown = true;
} finally {
assertTrue(exceptionThrown);
}
new Query<Query>(null) {}.withAlias("");
}
}