Skip to content

Commit 7fab503

Browse files
authored
ENG-960 Improve DX for base DG queries (#488)
Michael Gartner: Create a structure to distribute function arguments Marc-Antoine Parent: Push that structure to the helper function, some adjustments
1 parent 6cfc41b commit 7fab503

3 files changed

Lines changed: 669 additions & 180 deletions

File tree

apps/roam/src/components/settings/AdminPanel.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ const AdminPanel = () => {
160160
await getConcepts({
161161
supabase,
162162
spaceId,
163-
schemaLocalIds: showingSchema.sourceLocalId,
163+
scope: {
164+
schemas:
165+
showingSchema.sourceLocalId ===
166+
nodeSchemaSignature.sourceLocalId,
167+
type: "nodes",
168+
ofTypes: [showingSchema.sourceLocalId],
169+
},
164170
}),
165171
);
166172
} catch (e) {

packages/database/features/queryConcepts.feature

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,38 @@ Feature: Concept queries
1717
# Note: table syntax is explained in features/step-definitions/stepdefs.ts, look for `added to the database`.
1818
And Document are added to the database:
1919
| $id | source_local_id | created | last_modified | _author_id | _space_id |
20-
| d1 | ld1 | 2025/01/01 | 2025/01/01 | user1 | s1 |
21-
| d2 | ld2 | 2025/01/01 | 2025/01/01 | user1 | s1 |
22-
| d5 | ld5 | 2025/01/01 | 2025/01/01 | user2 | s1 |
23-
| d7 | ld7 | 2025/01/01 | 2025/01/01 | user1 | s1 |
20+
| d1 | ld1 | 2025/01/01 | 2025/01/01 | user1 | s1 |
21+
| d2 | ld2 | 2025/01/01 | 2025/01/01 | user1 | s1 |
22+
| d5 | ld5 | 2025/01/01 | 2025/01/01 | user2 | s1 |
23+
| d7 | ld7 | 2025/01/01 | 2025/01/01 | user1 | s1 |
2424
# Add Content as support for the Concept objects, esp. schemas
2525
And Content are added to the database:
2626
| $id | source_local_id | _document_id | text | created | last_modified | scale | _author_id | _space_id |
27-
| ct1 | lct1 | d1 | Claim | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
28-
| ct2 | lct2 | d2 | claim 1 | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
29-
| ct5 | lct5 | d5 | Opposes | 2025/01/01 | 2025/01/01 | document | user2 | s1 |
30-
| ct7 | lct7 | d7 | Hypothesis | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
27+
| ct1 | lct1 | d1 | Claim | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
28+
| ct2 | lct2 | d2 | claim 1 | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
29+
| ct5 | lct5 | d5 | Opposes | 2025/01/01 | 2025/01/01 | document | user2 | s1 |
30+
| ct7 | lct7 | d7 | Hypothesis | 2025/01/01 | 2025/01/01 | document | user1 | s1 |
3131
# First add schemas
3232
And Concept are added to the database:
3333
| $id | name | _space_id | _author_id | _represented_by_id | created | last_modified | @is_schema | _schema_id | @literal_content | @reference_content |
34-
| c1 | Claim | s1 | user1 | ct1 | 2025/01/01 | 2025/01/01 | true | | {} | {} |
35-
| c5 | Opposes | s1 | user1 | ct5 | 2025/01/01 | 2025/01/01 | true | | {"roles": ["target", "source"]} | {} |
36-
| c7 | Hypothesis | s1 | user1 | ct7 | 2025/01/01 | 2025/01/01 | true | | {} | {} |
34+
| c1 | Claim | s1 | user1 | ct1 | 2025/01/01 | 2025/01/01 | true | | {} | {} |
35+
| c5 | Opposes | s1 | user1 | ct5 | 2025/01/01 | 2025/01/01 | true | | {"roles": ["target", "source"]} | {} |
36+
| c7 | Hypothesis | s1 | user1 | ct7 | 2025/01/01 | 2025/01/01 | true | | {} | {} |
3737
# Then nodes referring to the schemas
3838
And Concept are added to the database:
3939
| $id | name | _space_id | _author_id | created | last_modified | @is_schema | _schema_id | @literal_content | @reference_content | _represented_by_id |
40-
| c2 | claim 1 | s1 | user1 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | ct2 |
41-
| c3 | claim 2 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | |
42-
| c4 | claim 3 | s1 | user3 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | |
43-
| c8 | hypothesis 1 | s1 | user3 | 2025/01/01 | 2025/01/01 | false | c7 | {} | {} | |
40+
| c2 | claim 1 | s1 | user1 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | ct2 |
41+
| c3 | claim 2 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | |
42+
| c4 | claim 3 | s1 | user3 | 2025/01/01 | 2025/01/01 | false | c1 | {} | {} | |
43+
| c8 | hypothesis 1 | s1 | user3 | 2025/01/01 | 2025/01/01 | false | c7 | {} | {} | |
4444
# Then relations (which refer to nodes)
4545
And Concept are added to the database:
4646
| $id | name | _space_id | _author_id | created | last_modified | @is_schema | _schema_id | @literal_content | @_reference_content |
47-
| c6 | opposes 1 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c5 | {} | {"target": "c3", "source": "c2"} |
48-
| c9 | opposes 2 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c5 | {} | {"target": "c8", "source": "c2"} |
47+
| c6 | opposes 1 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c5 | {} | {"target": "c3", "source": "c2"} |
48+
| c9 | opposes 2 | s1 | user2 | 2025/01/01 | 2025/01/01 | false | c5 | {} | {"target": "c8", "source": "c2"} |
4949

5050
Scenario Outline: Query all nodes
51-
And a user logged in space s1 and calling getConcepts with these parameters: '{"schemaLocalIds":[],"fetchNodes":null}'
51+
And a user logged in space s1 and calling getConcepts with these parameters: '{"scope":{"type":"all"}}'
5252
Then query results should look like this
5353
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @_reference_content |
5454
| c2 | claim 1 | s1 | user1 | false | c1 | {} |
@@ -59,54 +59,54 @@ Feature: Concept queries
5959
| c9 | opposes 2 | s1 | user2 | false | c5 | {"target": "c8", "source": "c2"} |
6060

6161
Scenario Outline: Query node schemas
62-
And a user logged in space s1 and calling getConcepts with these parameters: '{"fetchNodes":null}'
62+
And a user logged in space s1 and calling getConcepts with these parameters: '{"scope":{"schemas":true}}'
6363
Then query results should look like this
6464
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @reference_content | _represented_by_id |
6565
| c1 | Claim | s1 | user1 | true | | {} | {} | ct1 |
6666
| c5 | Opposes | s1 | user1 | true | | {"roles": ["target", "source"]} | {} | ct5 |
6767
| c7 | Hypothesis | s1 | user1 | true | | {} | {} | ct7 |
6868

6969
Scenario Outline: Query by node types
70-
And a user logged in space s1 and calling getConcepts with these parameters: '{"schemaLocalIds":["lct1"]}'
70+
And a user logged in space s1 and calling getConcepts with these parameters: '{"scope":{"ofTypes":["lct1"]}}'
7171
Then query results should look like this
7272
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @reference_content |
7373
| c2 | claim 1 | s1 | user1 | false | c1 | {} | {} |
7474
| c3 | claim 2 | s1 | user2 | false | c1 | {} | {} |
7575
| c4 | claim 3 | s1 | user3 | false | c1 | {} | {} |
7676

7777
Scenario Outline: Query by author
78-
And a user logged in space s1 and calling getConcepts with these parameters: '{"nodeAuthor":"user2","schemaLocalIds":[],"fetchNodes":null}'
78+
And a user logged in space s1 and calling getConcepts with these parameters: '{"scope":{"author":"user2","type":"all"}}'
7979
Then query results should look like this
8080
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @_reference_content |
8181
| c3 | claim 2 | s1 | user2 | false | c1 | {} | {} |
8282
| c6 | opposes 1 | s1 | user2 | false | c5 | {} | {"target": "c3", "source": "c2"} |
8383
| c9 | opposes 2 | s1 | user2 | false | c5 | {} | {"target": "c8", "source": "c2"} |
8484

8585
Scenario Outline: Query by relation type
86-
And a user logged in space s1 and calling getConcepts with these parameters: '{"inRelsOfTypeLocal":["lct5"],"schemaLocalIds":[]}'
86+
And a user logged in space s1 and calling getConcepts with these parameters: '{"relations":{"ofTypes":["lct5"]}}'
8787
Then query results should look like this
8888
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @_reference_content |
8989
| c2 | claim 1 | s1 | user1 | false | c1 | {} | {} |
9090
| c3 | claim 2 | s1 | user2 | false | c1 | {} | {} |
9191
| c8 | hypothesis 1 | s1 | user3 | false | c7 | {} | {} |
9292

9393
Scenario Outline: Query by related node type
94-
And a user logged in space s1 and calling getConcepts with these parameters: '{"inRelsToNodesOfTypeLocal":["lct7"],"schemaLocalIds":[]}'
94+
And a user logged in space s1 and calling getConcepts with these parameters: '{"relations":{"toNodeTypes":["lct7"]}}'
9595
Then query results should look like this
9696
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @_reference_content |
9797
| c2 | claim 1 | s1 | user1 | false | c1 | {} | {} |
9898
| c8 | hypothesis 1 | s1 | user3 | false | c7 | {} | {} |
99-
10099
# Note that the node is related to itself, unfortunate but hard to solve.
100+
101101
Scenario Outline: Query by author of related node
102-
And a user logged in space s1 and calling getConcepts with these parameters: '{"schemaLocalIds":[],"inRelsToNodesOfAuthor":"user3","relationFields":["id"],"relationSubNodesFields":["id"]}'
102+
And a user logged in space s1 and calling getConcepts with these parameters: '{"relations":{"author":"user3"},"fields":{"relations":["id"],"relationNodes":["id"]}}'
103103
Then query results should look like this
104104
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @_reference_content |
105105
| c2 | claim 1 | s1 | user1 | false | c1 | {} | {} |
106106
| c8 | hypothesis 1 | s1 | user3 | false | c7 | {} | {} |
107107

108108
Scenario Outline: Query by related node
109-
And a user logged in space s1 and calling getConcepts with these parameters: '{"schemaLocalIds":[],"inRelsToNodeLocalIds":["lct2"]}'
109+
And a user logged in space s1 and calling getConcepts with these parameters: '{"relations":{"toNodeIds":["lct2"]}}'
110110
Then query results should look like this
111111
| _id | name | _space_id | _author_id | @is_schema | _schema_id | @literal_content | @_reference_content |
112112
| c2 | claim 1 | s1 | user1 | false | c1 | {} | {} |

0 commit comments

Comments
 (0)