Determine why a Union type wasn't used in graphql schema #105

Open
opened 2023-05-16 12:45:37 +00:00 by dboreham · 2 comments
Owner

Our GraphQL endpoint returns registry records conforming to a property set schema with Value type defined here.

This is a struct or "sum" type, where all of string, json, reference are present but by convention all except one is null.
This is a way of implementing a variant, union, or "product" type.

But GraphQL has union types.
Curious to understand why we didn't use that capability.

Our GraphQL endpoint returns registry records conforming to a property set schema with `Value` type [defined here](https://github.com/cerc-io/laconicd/blob/main/gql/vulcanize/chiba-clonk/schema.graphql#L41). This is a struct or "sum" type, where all of `string`, `json`, `reference` are present but by convention all except one is null. This is a way of implementing a variant, union, or "product" type. But GraphQL [has union types](https://graphql.org/learn/schema/#union-types). Curious to understand why we didn't use that capability.
Owner

I suspect the answer relates to the fact that when defining a GraphQL union, all variants must be other objects, not scalars. So, we would have to wrap everything like IntVariant for int, etc. and perhaps that amount of boilerplate was deemed not worth it - I think @ashwinphatak's team would have to confirm, though.

(And to be pedantic, a sum type would be a union, what we have now is a product type)

I suspect the answer relates to the fact that when defining a GraphQL union, all variants must be other objects, not scalars. So, we would have to wrap everything like `IntVariant` for int, etc. and perhaps that amount of boilerplate was deemed not worth it - I think @ashwinphatak's team would have to confirm, though. (And to be pedantic, a sum type would be a union, what we have now is a product type)
roysc self-assigned this 2023-10-11 20:19:59 +00:00
Owner

Note: schema in #112 will use union types

Note: schema in https://git.vdb.to/cerc-io/laconicd/pulls/112 will use union types
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cerc-io/laconicd#105
No description provided.