# Query over user's POD

**URL:** <https://forum.solidproject.org/t/query-over-users-pod/2840>\
**Category:** Build a Solid App\
**Created:** [April 2, 2020, 12:03pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840 "2020-04-02T12:03:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![christian98](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@christian98](https://forum.solidproject.org/u/christian98)\
**Post date:** [April 2, 2020, 12:03pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/1 "2020-04-02T12:03:42Z")

</div>

Hi,  
I am trying to make a query(SPARQL) where given a folder I can list content of all resources in that folder. For example: A query with inbox as an endpoint that shows me the title and summary of all the notifications that are inside that folder.

An example of inbox would be this:

```auto
@prefix : <#>.
@prefix inbox: <>.
@prefix ldp: <http://www.w3.org/ns/ldp#>.
@prefix terms: <http://purl.org/dc/terms/>.
@prefix XML: <http://www.w3.org/2001/XMLSchema#>.
@prefix st: <http://www.w3.org/ns/posix/stat#>.
@prefix tur: <http://www.w3.org/ns/iana/media-types/text/turtle#>.

inbox:
    a ldp:BasicContainer, ldp:Container;
    terms:modified "2020-04-01T20:41:34Z"^^XML:dateTime;
    ldp:contains
        <1585184241983.ttl>, <1585190831744.ttl>, <1585437347737.ttl>,
        <1585755866235.ttl>;
    st:mtime 1585773694.755;
    st:size 4096.
<1585184241983.ttl>
    a tur:Resource, ldp:Resource;
    terms:modified "2020-04-01T16:36:56Z"^^XML:dateTime;
    st:mtime 1585759016.9;
    st:size 877.
<1585190831744.ttl>
    a tur:Resource, ldp:Resource;
    terms:modified "2020-04-01T16:43:35Z"^^XML:dateTime;
    st:mtime 1585759415.31;
    st:size 877.
<1585437347737.ttl>
    a tur:Resource, ldp:Resource;
    terms:modified "2020-04-01T16:59:30Z"^^XML:dateTime;
    st:mtime 1585760370.042;
    st:size 877.
<1585755866235.ttl>
    a tur:Resource, ldp:Resource;
    terms:modified "2020-04-01T16:35:53Z"^^XML:dateTime;
    st:mtime 1585758953.69;
    st:size 886.

```

An example of notification:

```auto
@prefix terms: <http://purl.org/dc/terms#>.
        @prefix as: <https://www.w3.org/ns/activitystreams#>.
        @prefix schema: <http://schema.org/>.
        @prefix solid: <https://www.w3.org/ns/solid/terms#>.
        @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
        @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
        
        <> a as:Offer;
            schema:license <https://creativecommons.org/licenses/by-sa/4.0/>;
            terms:title "Route share";
            as:summary "Testing";
            as:actor <https://christianpelaez98.solid.community/profile/card#me>;
            as:target <https://pruebaChristian.solid.community/profile/card#me>;
            as:object <https://christianpelaez98.solid.community/ejemplos/ruta1.ttl>;
            solid:read "true"^^xsd:boolean;
            as:published "2020-03-26T00:57:21.984Z"^^xsd:dateTime.

```

Anybody got an idea? I have searched the forum and issues but I have not found anything that talks about this. Thanks!!💃

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [April 2, 2020, 12:24pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/2 "2020-04-02T12:24:01Z")

</div>

Hi Christian, unfortunately Solid does not currently support SPARQL queries on Pods, so you’ll have to fetch the contents of all those files individually, I’m afraid.

---

<div class="post-metadata">

**Author:** ![christian98](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@christian98](https://forum.solidproject.org/u/christian98)\
**Post date:** [April 2, 2020, 12:39pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/3 "2020-04-02T12:39:05Z")

</div>

Okay ☹, thank you!!

---

<div class="post-metadata">

**Author:** ![Smag0](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/smag0/32/310_2.png) [@Smag0](https://forum.solidproject.org/u/Smag0)\
**Post date:** [April 2, 2020, 1:01pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/4 "2020-04-02T13:01:24Z")

</div>

I had same kind of question for Shighl lib, I’ve used a log.ttl file where is written this kind summary data. Talk at 16:00 😉

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [April 2, 2020, 1:16pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/5 "2020-04-02T13:16:36Z")

</div>

Using [RDF-easy](https://github.com/jeff-zucker/rdf-easy), here’s how:

```javascript
let contents = await rdf.query( containerURI, `
      SELECT ?uri ?size WHERE {
          <> ldp:contains ?uri. 
          ?uri stat:size ?size.
      }
`)
for(var c of contents){ 
     let thisNotifcation = c.uri
     // send a second query to c.uri to get data in each notification) 
}

```

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 3:31pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/6 "2021-02-21T15:31:15Z")

</div>

Hi @jeffz ,  
I could not find rdf-easy on npm. I tried running “npm install rdf-easy”. Am I doing something wrong?  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/solidproject/original/2X/c/c615b9db7883577f98608262de99b7d8120abffe.png)

Thanks

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 4:32pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/7 "2021-02-21T16:32:24Z")

</div>

I stopped development of rdf-easy because there are already so many rdf handlers and I have too many libraries to maintain. But I always did kind of like it. You should be able to clone or download the [github repo](https://github.com/jeff-zucker/rdf-easy). Let me know if you end up using it.

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 5:28pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/8 "2021-02-21T17:28:23Z")

</div>

Just tried:  
import auth2 from ‘solid-auth-cli’  
import RDFEasy from ‘…/lib/rdf-easy’;

const rdf = new RDFEasy(auth2)

```
if (_.isEmpty(exclude)) {
    try {
        file = await rdf.query(cache, `
            SELECT DISTINCT ?s {
                ?s ?p ?o .
            }
        `);
    } catch (e) {
        console.error(e)
    }
}

```

I get the following error. I also tried with solid-auth-client with no luck.  
Error: Fetcher: [https://jorge.pod.ideniox.com/outbox/cache.ttl](https://jorge.pod.ideniox.com/outbox/cache.ttl) Unauthenticated  
at Fetcher.failFetch (fetcher.js:1112)  
at fetcher.js:1815  
at async RDFeasy.\_load (rdflib-easy.js:82)  
at async RDFeasy.\_runQuery (rdflib-easy.js:32)  
at async RDFeasy.query (rdflib-easy.js:24)  
at async getNotifications (things.js:331)  
at async Notification.load (notification.js:11)

I understand you may not be in the mood to look onto a issue of a code you are not longer maintaining. Would you kindly be able to recommend any rdf handler?

Cheers.

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 5:42pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/9 "2021-02-21T17:42:34Z")

</div>

If you want to, you can probably fix that by changing two lines in rdf-easy.js. Find the two lines that define the fetcher.

```javascript
// CHANGE THIS IN BOTH PLACES IT OCCURS
this.fetcher = $rdf.fetcher(this.store,{fetch:this._auth.fetch})
// TO THIS
this.fetcher = $rdf.fetcher(this.store,{fetch:this._auth.fetch.bind(this._auth)})

```

If you try that and it works for you, let me know. See this list of [alternative linked data libraries](https://solidproject.org/developers/tools). Query-LDflex and Tripledoc are both very robust and well-maintained.

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 6:15pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/10 "2021-02-21T18:15:49Z")

</div>

If you have more questions about rdf-easy, I’m glad to try to answer them. @bourgeoa had talked about reviving and adding to the project so it’s not impossible it will continue.

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 6:23pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/11 "2021-02-21T18:23:33Z")

</div>

I have tried your suggestion but I got the same error. I am just trying to do select query and update query ttl the same way that solid does it for trusted apps for instance.

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 6:25pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/12 "2021-02-21T18:25:31Z")

</div>

I’ll download it and take a look.

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 6:29pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/13 "2021-02-21T18:29:06Z")

</div>

Just checking … you did perform a login before making the request?

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 6:35pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/14 "2021-02-21T18:35:16Z")

</div>

> [@jeffz](#):
>
> you did perform a login before making the request?

Yes, I have I use.  
import {AuthButton, LoggedIn} from “@solid/react”;

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 6:55pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/15 "2021-02-21T18:55:48Z")

</div>

using solid-auth-client instead of solid-auth-cli I get  
query.js:616 Uncaught TypeError: Cannot read property ‘initBindings’ of undefined  
at query.js:616

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 7:06pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/16 "2021-02-21T19:06:10Z")

</div>

You have to use the same auth library as when you login. Solid-auth-client is for browsers and solid-auth-cli is for nodejs so if you’re in a browser, only use solid-auth-client or the newer @inrupt/solid-client-authn-browser.

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 21, 2021, 7:36pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/17 "2021-02-21T19:36:51Z")

</div>

I use solid-auth-client which is the same I use for log in.  
In my example I do:

import auth from “solid-auth-client”;  
const $rdf = require(‘rdflib’)

const graph = $rdf.graph()  
const fetcher = $rdf.fetcher(graph,{fetch: auth.fetch.bind(auth)})  
await fetcher.load(cache)  
const j = await fetcher.store.query(` SELECT DISTINCT ?s { ?s ?p ?o . }`  
);

And I get a Uncaught TypeError: Cannot read property ‘initBindings’ of undefined

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 21, 2021, 8:27pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/18 "2021-02-21T20:27:20Z")

</div>

You’re missing the SPARQLToQuery step. Try this (use solid-auth-client instead of SolidNodeClient if in browser:

```javascript
import * as $rdf from 'rdflib';                                                 
import {SolidNodeClient} from 'solid-node-client';                                            
const auth = new SolidNodeClient();                                             
const store = $rdf.graph();                                                     
const fetcher = $rdf.fetcher(store,{fetch:auth.fetch.bind(auth)});              
                                                                                
const ex = "https://example.com/";                                              
store.add( $rdf.sym(ex+'Foo'), $rdf.sym(ex+'has'), 'Bar');                      
store.add( $rdf.sym(ex+'Baz'), $rdf.sym(ex+'has'), 'Bop');                      
let sparql = "SELECT ?s WHERE { ?s ?p 'Bar' . }";                               
let preparedQuery = $rdf.SPARQLToQuery(sparql,false,store)                     
store.query( preparedQuery, async(results) => {                                
  console.log(results['?s'].value); // prints "https://example.com/Foo"         
});                                                                             

```

---

<div class="post-metadata">

**Author:** ![ch1ch0gz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ch1ch0gz/32/2227_2.png) [@ch1ch0gz](https://forum.solidproject.org/u/ch1ch0gz)\
**Post date:** [February 22, 2021, 5:49pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/19 "2021-02-22T17:49:12Z")

</div>

Kinda stuck in here…sorry to pester.  
I have a file called test.ttl as below.

\<\> [http://example.org/has](http://example.org/has) [https://jorge.pod.ideniox.com/outbox/123123231123](https://jorge.pod.ideniox.com/outbox/123123231123) .  
[https://jorge.pod.ideniox.com/outbox/123123231123](https://jorge.pod.ideniox.com/outbox/123123231123) [https://example.org/message](https://example.org/message) “”“Hi!”"".  
﻿  
Built a row function to read the above ttl.

const readTTL = url =\> {  
return new Promise((resolve, reject) =\> {  
try {  
const store = $rdf.graph();  
const fetcher = $rdf.fetcher(store, {fetch: auth.fetch.bind(auth)})  
fetcher.load(url).then(() =\> {  
const query = ` SELECT DISTINCT ?s WHERE { ?s ?p ?o . } `;  
let resultSet = [];  
let preparedQuery = $rdf.SPARQLToQuery(query, false, store);  
store.query(preparedQuery, e =\> {  
resultSet.push(e)  
}, undefined, () =\> {  
resolve(resultSet)  
});  
});  
} catch (e) {  
reject(e);  
}  
})  
};

And I get the following output, which is not correct…

0: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
1: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
2: [?o: Collection, ?p: NamedNode, ?s: BlankNode]  
3: [?o: BlankNode, ?p: NamedNode, ?s: BlankNode]  
4: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
5: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
6: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
7: [?o: Literal, ?p: NamedNode, ?s: BlankNode]  
etc…

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [February 22, 2021, 9:11pm UTC](https://forum.solidproject.org/t/query-over-users-pod/2840/20 "2021-02-22T21:11:05Z")

</div>

Are you saying that the output is literally that, i.e. literally the string “NamedNode” as opposed to a NamedNode object? Because if it’s a NamedNode object, that is what I’d expect the return to be. And I’d expect to be able to get the subject NamedNode’s value with what I showed in the example above: results[’?s’].value.

[Next page](https://forum.solidproject.org/t/query-over-users-pod/2840.md?page=2)
