earthstar-project / earthstar-graphql

Query, sync and set data to earthstar workspaces using GraphQL.
GNU Affero General Public License v3.0
6 stars 1 forks source link

Add filter args to document fields #10

Closed sgwilym closed 3 years ago

sgwilym commented 3 years ago

Adds filtering to document fields, so you can write queries like this:

{
  workspaces {
    documents(pathPrefix: "/wiki") {
      ... on ES3Document {
        path
      }
    }
  }
}

Also supports the versionsByAuthor arg. Will be easy to add more QueryOpts from earthstar as they are implemented ( @cinnamon-bun seems like participatingAuthor isn't used in the most recently published release?)

Best of all, this opens the door to partial syncing.

Closes #6

cinnamon-bun commented 3 years ago

⭐ 💫

seems like participatingAuthor isn't used in the most recently published release?

It's there for memory but not sqlite yet.

query memory sqlite
versionsByAuthor implemented implemented
participatingAuthor implemented not yet
lastAuthor not yet not yet

Issue: Implement participatingAuthor query in sqlite

cinnamon-bun commented 3 years ago

P.S. you likely already saw this, but types.ts has the documentation about the different query options.

sgwilym commented 3 years ago

@cinnamon-bun I was referring to it a lot! But now that I have you here... I read it again and again but I wasn't able to understand what the difference between versionsByAuthor and participatingAuthor is. Could you help me out? 😅

cinnamon-bun commented 3 years ago

@sgwilym it's confusing. I don't know which kinds of queries we really need. Maybe I should remove some of these.

Example Data

most recent document versions are towards the right side
/path1: {author @a, content "1a"} {author @y, content "1y"}
/path2: {author @x, content "2x"} {author @a, content "2a"}
/path3: {author: @z, content "3z"}

Queries

The latest doc, by anyone, for any path that @a has touched {participatingAuthor: @a, includeHistory: false} --> 1y, 2a

All doc versions, by anyone, for any path that @a has touched {participatingAuthor: @a, includeHistory: true} --> 1a, 1y, 2x, 2a

Document versions by this author which are the latest in a path {versionsByAuthor: @a, includeHistory: false} --> 2a

All document versions by this author including non-latest ones {versionsByAuthor: @a, includeHistory: true} --> 1a, 2a

Paths where this author was the last writer; just the last doc (Note this is the same as versionsByAuthor when history is false) {lastAuthor: @a, includeHistory: false} --> 2a

Paths where this author was the last writer; and all history at that path {lastAuthor: @a, includeHistory: true} --> 2x, 2a

sgwilym commented 3 years ago

Ah, I had somehow missed this!

image

I kept thinking I was missing something because I kept reading versions and thinking "I thought only the latest version was kept...".

Thanks! I'm going to close this PR and merge in changes along with #11.