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

Optional fields vs null #12

Open cinnamon-bun opened 3 years ago

cinnamon-bun commented 3 years ago

The deleteAfter field is optional, but earthstar-graphql returns docs with deleteAfter: null.

I think I like null better actually. I might change the Earthstar spec to use null, thoughts? https://github.com/earthstar-project/earthstar/issues/45

sgwilym commented 3 years ago

As you saw in https://github.com/earthstar-project/earthstar/issues/45, nullable fields are the only option for a GraphQL server — either that or adding more types for documents with certain fields present/absent.

Copying what I wrote thre here as it's more related to earthstar-graphql:

Another way we can go, and one which could make sense for workspaceSignature, is to create multiple types e.g. PrivateWorkspaceES4Document (great name, right?), which has a non nullable workspaceSignature, and have regular ES4Document have no field at all. There would definitely be trade-offs to doing this, but the benefit is that it makes certain impossible states impossible, e.g. like having a document with no workspaceSignature in an invite only workspace.

GraphQL also has support for interfaces, so both the private workspace and public workspace document types could share a common ES4Document interface. Hmm, I quite like the sound of that, actually...