Skip to content

Annotated query handler #170

@tpluscode

Description

@tpluscode

To simplify implementing resources backed by a SPARQL query, I'd like to have a handler, possibly exported from a dedicated package, that would make it possible declaratively. For example

<>
  a kl:ResourceShape ;
  kl:api </api> ;
  sh:targetClass api:ExternalResource ;
  kl:handler
    [
      a kl:Handler ;
      kl:method "GET" ;
      code:implementedBy
        [
          a code:EcmaScriptModule ;
          code:link <node:@kopflos-cms/query#construct> ;
        ] ;
      code:arguments
        [
          arg:endpoint "lindas" ;
          arg:query
            [
              a code:SparqlQuery ;
              code:link <file:queries/external-resource.rq>
            ] ;
          arg:variables
            [
              arg:this [ sh:path schema:sameAs ] ;
            ] ;
        ]
    ] ;
.

Given the above, when a request for an instance of api:ExternalResource would be made, the handler would load the query from queries/external-resource.rq and run it against env.sparql.lindas endpoint.

If arg:endpoint would be omitted, the default endpoint should be used.

arg:variable maps resource contents to SPARQL inputs. The handler would follow sh:path from the request subject. Might also allow an imperative way

Open questions

  1. What happens when there are multiple values found by resolving arg:variables? Especially in the case of multiple variables. Do we just create VALUES clause with the cartesian product?
  2. How could we support federated queries?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions