Skip to content

Commit 0c93875

Browse files
authored
Merge branch 'master' into fixModelConfigBuildWarnings
2 parents 323d96a + e51178e commit 0c93875

File tree

7 files changed

+151
-18
lines changed

7 files changed

+151
-18
lines changed

elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/AggregationDataStoreIntegrationTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import javax.sql.DataSource;
7171
import javax.ws.rs.container.ContainerRequestContext;
7272
import javax.ws.rs.container.ContainerRequestFilter;
73+
import javax.ws.rs.core.MediaType;
7374
import javax.ws.rs.core.SecurityContext;
7475

7576
/**
@@ -1375,4 +1376,59 @@ public void testTimeDimensionArgumentsInFilter() throws Exception {
13751376

13761377
runQueryWithExpectedResult(graphQLRequest, expected);
13771378
}
1379+
1380+
@Test
1381+
public void testSchemaIntrospection() throws Exception {
1382+
String graphQLRequest = "{"
1383+
+ "__schema {"
1384+
+ " mutationType {"
1385+
+ " name "
1386+
+ " fields {"
1387+
+ " name "
1388+
+ " args {"
1389+
+ " name"
1390+
+ " defaultValue"
1391+
+ " }"
1392+
+ " }"
1393+
+ " }"
1394+
+ "}"
1395+
+ "}";
1396+
1397+
String query = toJsonQuery(graphQLRequest, new HashMap<>());
1398+
1399+
given()
1400+
.contentType(MediaType.APPLICATION_JSON)
1401+
.accept(MediaType.APPLICATION_JSON)
1402+
.body(query)
1403+
.post("/graphQL")
1404+
.then()
1405+
.statusCode(HttpStatus.SC_OK)
1406+
// Verify that the orderDetails Model has an argument "denominator".
1407+
.body("data.__schema.mutationType.fields.find { it.name == 'orderDetails' }.args.name[7] ", equalTo("denominator"));
1408+
1409+
graphQLRequest = "{"
1410+
+ "__type(name: \"OrderDetails\") {"
1411+
+ " name"
1412+
+ " fields {"
1413+
+ " name "
1414+
+ " args {"
1415+
+ " name"
1416+
+ " defaultValue"
1417+
+ " }"
1418+
+ " }"
1419+
+ "}"
1420+
+ "}";
1421+
1422+
query = toJsonQuery(graphQLRequest, new HashMap<>());
1423+
1424+
given()
1425+
.contentType(MediaType.APPLICATION_JSON)
1426+
.accept(MediaType.APPLICATION_JSON)
1427+
.body(query)
1428+
.post("/graphQL")
1429+
.then()
1430+
.statusCode(HttpStatus.SC_OK)
1431+
// Verify that the orderTotal attribute has an argument "precision".
1432+
.body("data.__type.fields.find { it.name == 'orderTotal' }.args.name[0]", equalTo("precision"));
1433+
}
13781434
}

elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/MetaDataStoreIntegrationTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ public void tableMetaDataTest() {
161161
"playerStats.highScore", "playerStats.dailyAverageScorePerPeriod"))
162162
.body("data.relationships.timeDimensions.data.id", containsInAnyOrder("playerStats.recordedDate",
163163
"playerStats.updatedDate"));
164+
// Verify Table Arguments
165+
given()
166+
.accept("application/vnd.api+json")
167+
.get("/table/orderDetails?include=arguments")
168+
.then()
169+
.statusCode(HttpStatus.SC_OK)
170+
.body("data.relationships.arguments.data.id", containsInAnyOrder("orderDetails.denominator"));
164171
}
165172

166173
@Test
@@ -295,6 +302,15 @@ public void metricMetaDataTest() {
295302
.body("data.attributes.arguments", nullValue()) // No Arguments were set.
296303
.body("data.relationships.table.data.id", equalTo("videoGame"));
297304

305+
// Verify Metric Arguments
306+
given()
307+
.accept("application/vnd.api+json")
308+
.get("/table/orderDetails/metrics/orderDetails.orderTotal?include=arguments")
309+
.then()
310+
.statusCode(HttpStatus.SC_OK)
311+
.body("data.attributes.name", equalTo("orderTotal"))
312+
.body("data.attributes.friendlyName", equalTo("orderTotal"))
313+
.body("data.relationships.arguments.data.id", containsInAnyOrder("orderDetails.orderTotal.precision"));
298314
}
299315

300316
@Test

elide-datastore/elide-datastore-aggregation/src/test/resources/configs/models/tables/SalesView.hjson

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
dbConnectionName: SalesDBConnection
88
cardinality: large
99
readAccess: guest user
10+
arguments:
11+
[
12+
{ // An argument that can be used to divide orderTotal to convert orders in Millions, Thousands, etc.
13+
name: denominator
14+
type: DECIMAL
15+
default: 1
16+
}
17+
]
1018
joins:
1119
[
1220
{
@@ -32,8 +40,17 @@
3240
{
3341
name: orderTotal
3442
type: DECIMAL
43+
// TODO : Use Arguments
3544
definition: 'SUM({{ $order_total }})'
3645
readAccess: admin.user
46+
arguments:
47+
[
48+
{ // An argument that can be used to divide orderTotal to convert orders in Millions, Thousands, etc.
49+
name: precision
50+
type: DECIMAL
51+
default: 0.00
52+
}
53+
]
3754
}
3855
]
3956
dimensions:

elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectionMaker.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.math.BigInteger;
5252
import java.util.ArrayList;
5353
import java.util.HashMap;
54+
import java.util.HashSet;
5455
import java.util.List;
5556
import java.util.Map;
5657
import java.util.Optional;
@@ -195,6 +196,10 @@ private EntityProjection createProjection(Type<?> entityType, Field entityField)
195196
.type(entityType)
196197
.pagination(PaginationImpl.getDefaultPagination(entityType, elideSettings));
197198

199+
// Add the Entity Arguments to the Projection
200+
projectionBuilder.arguments(new HashSet<>(
201+
getArguments(entityField, entityDictionary.getEntityArguments(entityType))
202+
));
198203
entityField.getSelectionSet().getSelections().forEach(selection -> addSelection(selection, projectionBuilder));
199204
entityField.getArguments().forEach(argument -> addArgument(argument, projectionBuilder));
200205

@@ -349,11 +354,10 @@ private void addArgument(Argument argument, EntityProjectionBuilder projectionBu
349354
addSorting(argument, projectionBuilder);
350355
} else if (ModelBuilder.ARGUMENT_FILTER.equals(argumentName)) {
351356
addFilter(argument, projectionBuilder);
352-
} else if (isEntityArgument(argumentName, entityDictionary, projectionBuilder.getType())) {
353-
addEntityArgument(argument, projectionBuilder);
354357
} else if (!ModelBuilder.ARGUMENT_OPERATION.equals(argumentName)
355358
&& !(ModelBuilder.ARGUMENT_IDS.equals(argumentName))
356-
&& !(ModelBuilder.ARGUMENT_DATA.equals(argumentName))) {
359+
&& !(ModelBuilder.ARGUMENT_DATA.equals(argumentName))
360+
&& !isEntityArgument(argumentName, entityDictionary, projectionBuilder.getType())) {
357361
addAttributeArgument(argument, projectionBuilder);
358362
}
359363
}
@@ -373,20 +377,6 @@ private static boolean isEntityArgument(String argumentName, EntityDictionary di
373377
.anyMatch(a -> a.getName().equals(argumentName));
374378
}
375379

376-
/**
377-
* Create a {@link com.yahoo.elide.core.request.Argument} object from GraphQL argument and attach it to the building
378-
* {@link EntityProjection}.
379-
*
380-
* @param argument graphQL argument
381-
* @param projectionBuilder projection that is being built
382-
*/
383-
private void addEntityArgument(Argument argument, EntityProjectionBuilder projectionBuilder) {
384-
projectionBuilder.argument(com.yahoo.elide.core.request.Argument.builder()
385-
.name(argument.getName())
386-
.value(variableResolver.resolveValue(argument.getValue()))
387-
.build());
388-
}
389-
390380
/**
391381
* Returns whether or not a GraphQL argument name corresponding to a pagination argument.
392382
*

elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ public GraphQLTest() {
4141

4242
dictionary.addArgumentToAttribute(ClassType.of(ParameterizedExample.class), "attribute",
4343
new ArgumentType("argument", ClassType.STRING_TYPE, "defaultValue"));
44+
dictionary.addArgumentToEntity(ClassType.of(ParameterizedExample.class),
45+
new ArgumentType("entityArgument", ClassType.STRING_TYPE, "defaultArgValue"));
4446
}
4547
}

elide-graphql/src/test/java/com/yahoo/elide/graphql/ModelBuilderTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ public void checkAttributeArguments() {
217217
assertEquals(Scalars.GraphQLString, bookType.getFieldDefinition(FIELD_PUBLISH_DATE).getArgument(TYPE).getType());
218218
}
219219

220+
@Test
221+
public void checkModelArguments() {
222+
// Add test arguments to entities
223+
dictionary.addArgumentToEntity(getClassType(Book.class), new ArgumentType("filterBook", ClassType.STRING_TYPE));
224+
dictionary.addArgumentToEntity(getClassType(Publisher.class), new ArgumentType("filterPublisher", ClassType.STRING_TYPE));
225+
dictionary.addArgumentToEntity(getClassType(Author.class), new ArgumentType("filterAuthor", ClassType.STRING_TYPE));
226+
227+
DataFetcher fetcher = mock(DataFetcher.class);
228+
ModelBuilder builder = new ModelBuilder(dictionary, new NonEntityDictionary(), fetcher, NO_VERSION);
229+
230+
GraphQLSchema schema = builder.build();
231+
232+
GraphQLObjectType root = schema.getQueryType();
233+
assertNotNull(root);
234+
assertNotNull(root.getFieldDefinition(FIELD_BOOK));
235+
236+
/* The root 'book' should have the "filterBook" argument defined */
237+
GraphQLFieldDefinition bookField = root.getFieldDefinition(FIELD_BOOK);
238+
assertNotNull(bookField.getArgument("filterBook"));
239+
240+
/* book.publisher is a "toOne" relationship and has the argument "filterPublisher" defined */
241+
GraphQLObjectType bookType = (GraphQLObjectType) schema.getType(TYPE_BOOK);
242+
GraphQLFieldDefinition publisherField = bookType.getFieldDefinition(FIELD_PUBLISHER);
243+
assertNotNull(publisherField.getArgument("filterPublisher"));
244+
245+
/* book.authors is a 'to many' relationship and has the argument "filterAuthor" defined */
246+
GraphQLFieldDefinition authorField = bookType.getFieldDefinition(FIELD_AUTHORS);
247+
assertNotNull(authorField.getArgument("filterAuthor"));
248+
}
249+
220250
private GraphQLObjectType getConnectedType(GraphQLObjectType root, String connectionName) {
221251
GraphQLList edgesType = (GraphQLList) root.getFieldDefinition(EDGES).getType();
222252
GraphQLObjectType rootType = (GraphQLObjectType)

elide-graphql/src/test/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectMakerTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public void testParameterizedAttribute() {
5050
String graphQLRequest = document(
5151
selection(
5252
field(
53-
"parameterizedExample",
53+
"parameterizedExample", arguments(
54+
argument("entityArgument", "xyz", true)
55+
),
5456
selections(
5557
field("attribute", arguments(
5658
argument("argument", "abc", true)
@@ -66,6 +68,16 @@ public void testParameterizedAttribute() {
6668

6769
EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
6870

71+
// Verify Entity Argument
72+
assertEquals(1, projection.getArguments().size());
73+
74+
Argument entityArgument = projection.getArguments().iterator().next();
75+
76+
assertEquals("entityArgument", entityArgument.getName());
77+
assertEquals(String.class, entityArgument.getType());
78+
assertEquals("xyz", entityArgument.getValue());
79+
80+
// Verify Attribute Argument
6981
assertEquals(1, projection.getAttributes().size());
7082

7183
Attribute attribute = projection.getAttributes().iterator().next();
@@ -98,6 +110,16 @@ public void testParameterizedAttributeDefaultValue() {
98110

99111
EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
100112

113+
// Verify Entity Argument
114+
assertEquals(1, projection.getArguments().size());
115+
116+
Argument entityArgument = projection.getArguments().iterator().next();
117+
118+
assertEquals("entityArgument", entityArgument.getName());
119+
assertEquals(String.class, entityArgument.getType());
120+
assertEquals("defaultArgValue", entityArgument.getValue());
121+
122+
// Verify Attribute Argument
101123
assertEquals(1, projection.getAttributes().size());
102124

103125
Attribute attribute = projection.getAttributes().iterator().next();

0 commit comments

Comments
 (0)