Skip to content

Commit 77ad134

Browse files
committed
Improve Solid usage descriptions
1 parent d61dc87 commit 77ad134

3 files changed

Lines changed: 68 additions & 18 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"remark-gfm": "^1.0.0",
2424
"rss": "^1.2.2",
2525
"sass": "^1.26.10"
26-
}
26+
},
27+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2728
}

pages/docs/1_query/advanced/solid.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,58 @@ Solid achieves this by giving everyone control over their own **personal data po
1212
Applications are completely separate, and have to ask permission to access your data.
1313

1414
Since Solid and Comunica have a compatible technology stack,
15-
Comunica can be used to query over Solid data pods.
16-
The default [Comunica SPARQL engine](/docs/query/getting_started/query_cli/)
17-
can directly be used to query over public Solid data pods as long as you are querying over public data.
18-
If you want to **query over data pods that require authentication**,
19-
you can use one of the approaches mentioned below.
15+
Comunica can be used to query over one or more Solid data pods.
2016

21-
## Query pods with a custom fetch function
17+
This document describes the different approaches that exist for querying Solid pods using Comunica.
2218

23-
Libraries such as [@inrupt/solid-client-authn-node](https://www.npmjs.com/package/@inrupt/solid-client-authn-node)
24-
and [@inrupt/solid-client-authn-browser](https://www.npmjs.com/package/@inrupt/solid-client-authn-browser)
25-
allow you to authenticate with your Solid WebID.
19+
In summary, there are three main approaches for querying Solid pods with Comunica:
20+
1. **Query specific public documents**: Comunica SPARQL (`@comunica/query-sparql`)
21+
2. **Query specific private documents**: Comunica SPARQL (`@comunica/query-sparql`) and pass authenticated fetch function, or Comunica SPARQL Solid (`@comunica/query-sparql-solid`)
22+
3. **Query pods using link traversal** (_experimental_): Comunica SPARQL Link Traversal Solid (`@comunica/query-sparql-link-traversal-solid`)
23+
24+
## 1. Query specific public documents in Solid pods
25+
26+
If you have prior knowledge of what documents in a Solid pod contain the data you want to query over,
27+
and these documents do not require authentication,
28+
then you can directly query over these documents using the default [Comunica SPARQL engine](/docs/query/getting_started/query_cli/)
29+
as a traditional federated query.
30+
31+
**Querying from JavaScript**:
32+
```typescript
33+
import { QueryEngine } from '@comunica/query-sparql';
34+
35+
const myEngine = new QueryEngine();
36+
37+
const bindingsStream = await myEngine.queryBindings(`
38+
SELECT * { ?s ?p ?o }`, {
39+
sources: ['https://pod1.org/document1.ttl', 'https://pod2.org/document2.ttl'],
40+
});
41+
```
42+
43+
**Querying from the command line**:
44+
```bash
45+
$ comunica-sparql https://pod1.org/document1.ttl https://pod2.org/document2.ttl \
46+
"SELECT * { ?s ?p ?o }"
47+
```
48+
49+
<div class="note">
50+
While the examples above show querying over multiple documents in Solid pods,
51+
<a href="/docs/query/advanced/source_types/">other types of sources</a> (such as SPARQL endpoints, RDF files, etc.) can also be used in combination with Solid pods in the same query.
52+
</div>
53+
54+
## 2. Query specific private documents in Solid pods
55+
56+
Similar to the previous approach, you can also query specific documents in Solid pods that require authentication.
57+
58+
For this, you can use Comunica in combination with libraries such as [@inrupt/solid-client-authn-node](https://www.npmjs.com/package/@inrupt/solid-client-authn-node)
59+
and [@inrupt/solid-client-authn-browser](https://www.npmjs.com/package/@inrupt/solid-client-authn-browser) that allow you to authenticate with your Solid WebID.
2660
These libraries provide a custom `fetch` function, using which you can execute authenticated HTTP requests.
2761

2862
You can forward this fetch function to Comunica SPARQL to make it perform authenticated queries to pods as shown below.
2963

64+
**Querying from JavaScript with Comunica SPARQL**:
3065
```typescript
31-
import { QueryEngine } from '@comunica/query-sparql-solid';
66+
import { QueryEngine } from '@comunica/query-sparql';
3267
import { Session } from '@inrupt/solid-client-authn-node';
3368

3469
const session = new Session();
@@ -47,15 +82,19 @@ const bindingsStream = await myEngine.queryBindings(`
4782
});
4883
```
4984

50-
## Query pods with an existing Solid session
85+
<div class="note">
86+
You can also try out authenticated queries to your Solid pods via our
87+
<a href="https://query.comunica.dev/">live web client</a>.
88+
To enable authentication, click the gear icon, fill in your Identity Provider, and press the "Log in" button.
89+
</div>
5190

52-
[Comunica SPARQL Solid](https://github.com/comunica/comunica-feature-solid/tree/master/engines/query-sparql-solid)
53-
allows you to pass your authenticated Solid session object.
91+
Alternatively, you can use the dedicated [Comunica SPARQL Solid](https://github.com/comunica/comunica-feature-solid/tree/master/engines/query-sparql-solid),
92+
which allows you to pass your authenticated Solid session object.
5493
Hereafter, we list some examples on how to use it from JavaScript and the command line.
5594
Please refer to the [README of Comunica SPARQL Solid](https://github.com/comunica/comunica-feature-solid/tree/master/engines/query-sparql-solid#readme)
5695
for more details.
5796

58-
**Querying from JavaScript**:
97+
**Querying from JavaScript Comunica SPARQL Solid**:
5998
```typescript
6099
import { QueryEngine } from '@comunica/query-sparql-solid';
61100
import { Session } from '@inrupt/solid-client-authn-node';
@@ -101,21 +140,21 @@ Please be aware that that there are several [open known issues](https://github.c
101140

102141
[LDflex](/docs/query/usage/#ldflex) and [GraphQL-LD](/docs/query/usage/#graphql-ld) are examples of tools that ship with Comunica SPARQL Solid.
103142

104-
## Query pods using link traversal
143+
## 3. Query pods using link traversal
105144

106145
The approaches for querying Solid mentioned above require you to know upfront in which pod and in which documents
107146
your data resides before you can query over it.
108147
[_Comunica SPARQL Link Traversal Solid_](https://github.com/comunica/comunica-feature-link-traversal/tree/master/engines/query-sparql-link-traversal-solid#comunica-sparql-link-traversal)
109148
provides a way to query over Solid pods without having to know beforehand in which documents the necessary data resides in.
110149
It does this by following links between documents _during query execution_.
111150

112-
This is still an experimental query approach, which does not yet work well for complex queries.
151+
This is still an **experimental query approach**, which does not yet work well for complex queries.
113152
Learn more about active [research on link traversal in Solid](https://comunica.dev/research/link_traversal/).
114153

115154
The example below executes a query across multiple simulated Solid pods to find all messages by a certain creator:
116155

117156
```typescript
118-
import { QueryEngine } from '@comunica/query-sparql-solid';
157+
import { QueryEngine } from '@comunica/query-sparql-link-traversal-solid';
119158

120159
const myEngine = new QueryEngine();
121160
const bindingsStream = await myEngine.queryBindings(`

pages/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export default function Home() {
5353
<p>Learn how to configure or extend</p>
5454
</a>
5555

56+
<a href="docs/query/advanced/solid" className="card">
57+
<h3>Query Solid pods &rarr;</h3>
58+
<p>Query one or more Solid pods</p>
59+
</a>
60+
61+
<a href="docs/query/advanced/mcp/" className="card">
62+
<h3>Comunica MCP &rarr;</h3>
63+
<p>Connect Comunica with AI Agents</p>
64+
</a>
65+
5666
<a href="https://opencollective.com/comunica-association" className="card">
5767
<h3>Donate &rarr;</h3>
5868
<p>Sponsor via Open Collective</p>

0 commit comments

Comments
 (0)