Skip to content

Allow casting of type variables to value variables #329

Open
@shreyas1599

Description

@shreyas1599

Problem to Solve

Currently, instance variables can be casted into value variables and the below query is valid.

match $entity isa entity-name has attribute-one $attributeOne;
?attributeValue = $attributeOne;
fetch nestedQuery: {
    match $anotherEntity is another-entity-name, has attribute-two ?attributeValue;
    fetch $anotherEntity: attribute;
};

But the same cannot be done with a type variable. For example, the below query is invalid. The below use case is to fetch the super types of an entity and then use a subquery to fetch another entity with an attribute filter that depends on the label of the supertype. Essentially, it's trying to cast a type variable into a value variable.

Query 1

match $someEntity isa $someEntityType, has id "some id";
$someEntityType sub entity;
not { $someEntityType sub someEntityType; };
?someEntityTypeValue = $someEntityType; # illegal operation
fetch $someEntityType;
metadataOfSomeEntity: {
    match $metadata isa metadata, has entity-type ?someEntityTypeValue;
    fetch $metadata: attribute;
};

Current Workaround

To run the aforementioned query, first get the labels of $someEntityType and then pass them into another query to run the sub query from above (metadataOfSomeEntity) either as a single query by using the OR operator or running them as separate queries for each of the labels.

Proposed Solution

To be able to run Query 1 without splitting it into >1 queries - support the casting of type variables to value variables.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions