hypermedia-app / Alcaeus

Hydra core hypermedia library
https://alcaeus.hydra.how
MIT License
61 stars 3 forks source link

`get` method always returns null #258

Open johnslaughter-ihsmarkit opened 2 years ago

johnslaughter-ihsmarkit commented 2 years ago

I'm using the current published version of alcaeus (1.3.1). So far I have been unable to fetch property information using the get method. The typed helper method all seem to work however. I believe that the issue might stem from the rdfine lib - but I haven't had a chance to check that out yet.

EDIT: On second look, I believe that the issue stems from the implementation of getArray in rdfine which filters out all properties that are not named or blank nodes.

https://github.com/tpluscode/rdfine/blob/377c603b222c30f75e8ecfe1ae6cd7dbfce5ccaf/packages/core/RdfResource.ts#L240

tpluscode commented 2 years ago

Uh, yea, essentially the same problem that was #248. Sorry about that

To be honest I'm less sure how I'd want to tackle this. The general idea behind rdfine is to build strong-typed interfaces proxying RDF properties.

So instead of resource.get('http://example.com/myProperty') you would type resource.myProperty

Have you seen this on the docs page: https://alcaeus.hydra.how/latest/#/representations/mixins ?

johnslaughter-ihsmarkit commented 2 years ago

That is helpful, thanks! Yes - I've seen the entry on mixins. For some background, I'm building a generic semantic api explorer to increase my own knowledge. For now, I'll be using the property indexer on the resource (I still want to refer to the properties by their vocab)

tpluscode commented 2 years ago

If you intend to access the graph in the most generic way then maybe you don't really need the object model that much? rdfine, which sits inside alcaeus works best for closed-world models. The representation of the hydra vocab for example is generated and packaged as @rdfine/hydra.

For API- and case-specific model you may be working against the grain here. Instead, I could advise an approach where you describe your graphs in SHACL for example and base your code on the properties.

A core design of rdfine is that the RDF/JS representation is easily accessible so that you can consume the graph using other tools and not only the OOP models. See below and example where I reworked the example from the docs to use SHACL paths for accessing data inside resource returned from the example API

https://runkit.com/embed/g8u373kz6n72

Of course, the returned values are plain RDF/JS objects