use of com.yahoo.elide.core.dictionary.ArgumentType in project elide by yahoo.
the class AggregationDataStore method populateEntityDictionary.
/**
* Populate an {@link EntityDictionary} and use this dictionary to construct a {@link QueryEngine}.
* @param dictionary the dictionary
*/
@Override
public void populateEntityDictionary(EntityDictionary dictionary) {
if (dynamicCompiledClasses != null && dynamicCompiledClasses.size() != 0) {
dynamicCompiledClasses.stream().filter((type) -> !IS_TYPE_HIDDEN.test(type)).forEach(dynamicLoadedClass -> {
dictionary.bindEntity(dynamicLoadedClass, IS_FIELD_HIDDEN);
validateModelExpressionChecks(dictionary, dynamicLoadedClass);
dictionary.bindPermissionExecutor(dynamicLoadedClass, aggPermissionExecutor);
});
}
dictionary.getScanner().getAnnotatedClasses(AGGREGATION_STORE_CLASSES).stream().filter((type) -> !IS_TYPE_HIDDEN.test(ClassType.of(type))).forEach(cls -> {
dictionary.bindEntity(cls, IS_FIELD_HIDDEN);
validateModelExpressionChecks(dictionary, ClassType.of(cls));
dictionary.bindPermissionExecutor(cls, aggPermissionExecutor);
});
for (Table table : queryEngine.getMetaDataStore().getMetaData(ClassType.of(Table.class))) {
/* Add 'grain' argument to each TimeDimensionColumn */
for (TimeDimension timeDim : table.getAllTimeDimensions()) {
dictionary.addArgumentToAttribute(dictionary.getEntityClass(table.getName(), table.getVersion()), timeDim.getName(), new ArgumentType("grain", ClassType.STRING_TYPE, timeDim.getDefaultGrain().getGrain()));
}
/* Add argument to each Column */
for (Column col : table.getAllColumns()) {
for (ArgumentDefinition arg : col.getArgumentDefinitions()) {
dictionary.addArgumentToAttribute(dictionary.getEntityClass(table.getName(), table.getVersion()), col.getName(), new ArgumentType(arg.getName(), ValueType.getType(arg.getType()), arg.getDefaultValue()));
}
}
/* Add argument to each Table */
for (ArgumentDefinition arg : table.getArgumentDefinitions()) {
dictionary.addArgumentToEntity(dictionary.getEntityClass(table.getName(), table.getVersion()), new ArgumentType(arg.getName(), ValueType.getType(arg.getType()), arg.getDefaultValue()));
}
}
}
use of com.yahoo.elide.core.dictionary.ArgumentType in project elide by yahoo.
the class MatchesTemplateVisitorTest method setup.
@BeforeEach
public void setup() {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStats.class);
dictionary.bindEntity(Player.class);
dictionary.addArgumentToAttribute(dictionary.getEntityClass("playerStats", EntityDictionary.NO_VERSION), "recordedDate", new ArgumentType("grain", ClassType.STRING_TYPE, TimeGrain.DAY));
dialect = RSQLFilterDialect.builder().dictionary(dictionary).addDefaultArguments(false).build();
}
use of com.yahoo.elide.core.dictionary.ArgumentType in project elide by yahoo.
the class ModelBuilderTest method checkModelArguments.
@Test
public void checkModelArguments() {
// Add test arguments to entities
dictionary.addArgumentToEntity(ClassType.of(Book.class), new ArgumentType("filterBook", ClassType.STRING_TYPE));
dictionary.addArgumentToEntity(ClassType.of(Publisher.class), new ArgumentType("filterPublisher", ClassType.STRING_TYPE));
dictionary.addArgumentToEntity(ClassType.of(Author.class), new ArgumentType("filterAuthor", ClassType.STRING_TYPE));
DataFetcher fetcher = mock(DataFetcher.class);
ModelBuilder builder = new ModelBuilder(dictionary, new NonEntityDictionary(DefaultClassScanner.getInstance(), CoerceUtil::lookup), fetcher, NO_VERSION);
GraphQLSchema schema = builder.build();
GraphQLObjectType root = schema.getQueryType();
assertNotNull(root);
assertNotNull(root.getFieldDefinition(FIELD_BOOK));
/* The root 'book' should have the "filterBook" argument defined */
GraphQLFieldDefinition bookField = root.getFieldDefinition(FIELD_BOOK);
assertNotNull(bookField.getArgument("filterBook"));
/* book.publisher is a "toOne" relationship and has the argument "filterPublisher" defined */
GraphQLObjectType bookType = (GraphQLObjectType) schema.getType(TYPE_BOOK);
GraphQLFieldDefinition publisherField = bookType.getFieldDefinition(FIELD_PUBLISHER);
assertNotNull(publisherField.getArgument("filterPublisher"));
/* book.authors is a 'to many' relationship and has the argument "filterAuthor" defined */
GraphQLFieldDefinition authorField = bookType.getFieldDefinition(FIELD_AUTHORS);
assertNotNull(authorField.getArgument("filterAuthor"));
}
use of com.yahoo.elide.core.dictionary.ArgumentType in project elide by yahoo.
the class ModelBuilderTest method checkAttributeArguments.
@Test
public void checkAttributeArguments() {
Set<ArgumentType> arguments = new HashSet<>();
arguments.add(new ArgumentType(SORT, ClassType.of(Sorting.SortOrder.class)));
arguments.add(new ArgumentType(TYPE, ClassType.STRING_TYPE));
dictionary.addArgumentsToAttribute(ClassType.of(Book.class), FIELD_PUBLISH_DATE, arguments);
DataFetcher fetcher = mock(DataFetcher.class);
ModelBuilder builder = new ModelBuilder(dictionary, new NonEntityDictionary(DefaultClassScanner.getInstance(), CoerceUtil::lookup), fetcher, NO_VERSION);
GraphQLSchema schema = builder.build();
GraphQLObjectType bookType = getConnectedType((GraphQLObjectType) schema.getType(TYPE_BOOK_CONNECTION), null);
assertEquals(2, bookType.getFieldDefinition(FIELD_PUBLISH_DATE).getArguments().size());
assertTrue(bookType.getFieldDefinition(FIELD_PUBLISH_DATE).getArgument(SORT).getType() instanceof GraphQLEnumType);
assertEquals(Scalars.GraphQLString, bookType.getFieldDefinition(FIELD_PUBLISH_DATE).getArgument(TYPE).getType());
}
Aggregations