Search in sources :

Example 1 with ArgumentType

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()));
        }
    }
}
Also used : ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Arrays(java.util.Arrays) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) Join(com.yahoo.elide.datastores.aggregation.annotation.Join) AccessibleObject(com.yahoo.elide.core.type.AccessibleObject) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) PermissionExecutor(com.yahoo.elide.core.security.PermissionExecutor) Function(java.util.function.Function) ClassType(com.yahoo.elide.core.type.ClassType) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ToString(lombok.ToString) ParseTree(org.antlr.v4.runtime.tree.ParseTree) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) RequestScope(com.yahoo.elide.core.RequestScope) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Check(com.yahoo.elide.core.security.checks.Check) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) NonNull(lombok.NonNull) Predicate(java.util.function.Predicate) ValueType(com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) AggregationStorePermissionExecutor(com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Objects(java.util.Objects) List(java.util.List) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Builder(lombok.Builder) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) QueryLogger(com.yahoo.elide.datastores.aggregation.core.QueryLogger) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType)

Example 2 with ArgumentType

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();
}
Also used : ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ArgumentType

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"));
}
Also used : Book(example.Book) GraphQLObjectType(graphql.schema.GraphQLObjectType) Author(example.Author) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Publisher(example.Publisher) DataFetcher(graphql.schema.DataFetcher) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) GraphQLSchema(graphql.schema.GraphQLSchema) Test(org.junit.jupiter.api.Test)

Example 4 with ArgumentType

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());
}
Also used : GraphQLEnumType(graphql.schema.GraphQLEnumType) Book(example.Book) GraphQLObjectType(graphql.schema.GraphQLObjectType) DataFetcher(graphql.schema.DataFetcher) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) GraphQLSchema(graphql.schema.GraphQLSchema) HashSet(java.util.HashSet) Sorting(com.yahoo.elide.core.request.Sorting) Test(org.junit.jupiter.api.Test)

Aggregations

ArgumentType (com.yahoo.elide.core.dictionary.ArgumentType)4 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)2 Book (example.Book)2 DataFetcher (graphql.schema.DataFetcher)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 Test (org.junit.jupiter.api.Test)2 ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 RequestScope (com.yahoo.elide.core.RequestScope)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 Sorting (com.yahoo.elide.core.request.Sorting)1 PermissionExecutor (com.yahoo.elide.core.security.PermissionExecutor)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)1 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)1 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)1 ClassType (com.yahoo.elide.core.type.ClassType)1 Type (com.yahoo.elide.core.type.Type)1