github.com/cayleygraph/cayley@v0.7.7/docs/mql.md (about)

     1  # MQL Guide
     2  
     3  ## General
     4  
     5  Cayley's MQL implementation is a work-in-progress clone of [Freebase's MQL API](https://developers.google.com/freebase/mql/). At the moment, it supports very basic queries without some of the extended features. It also aims to be database-agnostic, meaning that the schema inference from Freebase does not \(yet\) apply.
     6  
     7  Every JSON Object can be thought of as a node in the graph, and wrapping an object in a list means there may be several of these, or it may be repeated. A simple query like:
     8  
     9  ```javascript
    10  [{
    11    "id": null
    12  }]
    13  ```
    14  
    15  Is equivalent to all nodes in the graph, where "id" is the special keyword for the value of the node.
    16  
    17  Predicates are added to the object to specify constraints.
    18  
    19  ```javascript
    20  [{
    21    "id": null,
    22    "some_predicate": "some value"
    23  }]
    24  ```
    25  
    26  Predicates can take as values objects or lists of objects \(subqueries\), strings and numbers \(literal IDs that must match -- equivalent to the object {"id": "value"}\) or null, which indicates that, while the object must have a predicate that matches, the matching values will replace the null. A single null is one such value, an empty list will be filled with all such values, as strings.
    27  
    28  ## Keywords
    29  
    30  * `id`: The value of the node.
    31  
    32  ## Reverse Predicates
    33  
    34  Predicates always assume a forward direction. That is,
    35  
    36  ```javascript
    37  [{
    38    "id": "A",
    39    "some_predicate": "B"
    40  }]
    41  ```
    42  
    43  will only match if the quad
    44  
    45  ```text
    46  A some_predicate B .
    47  ```
    48  
    49  exists. In order to reverse the directions, "!predicates" are used. So that:
    50  
    51  ```javascript
    52  [{
    53    "id": "A",
    54    "!some_predicate": "B"
    55  }]
    56  ```
    57  
    58  will only match if the quad
    59  
    60  ```text
    61  B some_predicate A .
    62  ```
    63  
    64  exists.
    65  
    66  ## Multiple Predicates
    67  
    68  JSON does not specify the behavior of objects with the same key. In order to have separate constraints for the same predicate, the prefix "@name:" can be applied to any predicate. This is slightly different from traditional MQL in that fully-qualified http paths may be common predicates, so we have an "@name:" prefix instead.
    69  
    70  ```javascript
    71  [{
    72    "id": "A",
    73    "@x:some_predicate": "B",
    74    "@y:some_predicate": "C"
    75  
    76  }]
    77  ```
    78  
    79  Will only match if _both_
    80  
    81  ```text
    82  A some_predicate B .
    83  A some_predicate C .
    84  ```
    85  
    86  exist.
    87  
    88  This combines with the reversal rule to create paths like `"@a:!some_predicate"`
    89