Testing Typed Quad values and GraphQL


#1

I would like to play with those features, is there a quick guide I can follow so I can play with those features? For GraphQL I can probably follow the thread above.


#2

GraphQL

GraphQL is not yet ready to be included into main source tree. But I think it would be soon. I need to address the naming problem first. For now you may try experimental binary (build from #449) or Docker version from original post.

Types

Regarding types, you can just import the data and that’s it - you are already using them! The only difference you may notice with unmodified dataset - it’s the presence of IRIs (nodes with <>). Old importer drops type information, thus "bob" and <bob> became the same node. Now they are separate, so you’ll need to change your queries accordingly.

For example, with data:

<bob> <name> "Bob" .
<bob> <follows> <fred>

Old query looks like this:

g.V().Has("name","Bob").Out("follows").All()

The new one will be:

g.V().Has("<name>","Bob").Out("<follows>").All()

For more context of why it’s necessary you might want to check Types from JS.

But it’s not the end of the story, you can do more interesting things with types. You can modify the dataset to include more type information. Most of examples how it can be done can be found in RDF concepts. In short, typed values are expressed in this way in nquads:

"10"^^<http://schema.org/Integer>

Meaning we have value "10" of type <http://schema.org/Integer>.

Cayley supports few basic data types additionally to raw literals, IRIs and BNodes:

Integer

"10"^^<http://schema.org/Integer>
"10"^^<http://www.w3.org/2001/XMLSchema#integer>

Float

"1E+23"^^<http://schema.org/Float>
"1E+23"^^<http://www.w3.org/2001/XMLSchema#double>

Boolean

"True"^^<http://schema.org/Boolean>
"True"^^<http://www.w3.org/2001/XMLSchema#boolean>

DateTime

"2005-08-09T18:31:42+03"^^<http://schema.org/DateTime>
"2005-08-09T18:31:42+03"^^<http://www.w3.org/2001/XMLSchema#dateTime>

As one may notice, only two vocabularies are supported for now: schema.org and XSD. Later an ability to add any new type aliases will be added via sameAs mechanism.

All other values are treated as opaque and will be saved without any changes.

Usage

Now, what can you do with those types?

First of all, Cayley will now preserve any (even unknown) type information you write. This is useful if you use Cayley as a library, because now it’s not necessary to encode and decode data that is passed to the database.

Comparison operation is available for types described above. This means range queries can now be written without additional JS code. Simple range query will look like this:

g.V().Filter( gt(10), lte(15) ).All() // all nodes > 10 and <= 15

Only few operators are supported for now: lt, lte, gt, gte.

Gremlin interoperability is also improved. For example, JS numbers and dates are automatically converted to their RDF analogs, this means you don’t need to write the whole '"10"^^<http://schema.org/Integer>' thing as value in JS, simply 10 will work. You can alternatively force a specific type for a value with helpers:

raw("bob") // assumes value is already nquad-escaped; will not be modified by database at all
iri("bob") // becomes <bob> (IRI) in nquads
bnode("bob") // becomes _:bob (blank node) in nquads
str("<html>") // becomes "<html>" (string literal)
lang("Bob","en") // language-annotated string "Bob"@en
typed("10","xsd:integer") // type-annotated value "10"^^<xsd:integer>

But in any case, usage of all of these features depends on the schema of your application.


RFHT: Date Range Searching
#3

Thanks for the detailed reply!


#4

Do date types currently support the comparison operators? Meaning, can I get back all the nodes with the predicate of “added_on” between X date and Y date?


#5

Sure, it should work.


#6

Now both GraphQL and types are available in #449.