Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support for jsonb Type in Schema #226

Open
pavlovdog opened this issue Sep 24, 2024 · 1 comment
Open

Feature request: Support for jsonb Type in Schema #226

pavlovdog opened this issue Sep 24, 2024 · 1 comment
Labels
Enhancement New feature or request Feature

Comments

@pavlovdog
Copy link

pavlovdog commented Sep 24, 2024

Description

Currently, I am trying to define a GraphQL schema that includes a field capable of representing different types of objects. Here's an example schema:

type One {
  id: ID!
  text: String!
}

type Two {
  id: ID!
  text: String!
  value: BigInt!
}

union OneOrTwo = One | Two

type MyEntity {
  id: ID!
  oneOrTwo: OneOrTwo
}

Unfortunately, I encountered the following error while attempting to generate TypeScript code:

Error: Failed cli execution

Caused by:
    0: Failed parsing config
    1: Parsing schema file for config
    2: Failed converting schema doc to schema struct
    3: No type definition 'OneOrTwo' exists in schema

The workaround suggestion was to use an enum, but this doesn't allow for complex payloads, which I need.

Request

It would be great if the schema could support a jsonb type, like so:

type MyEntity {
  id: ID!
  oneOrTwo: Jsonb
}

This way, the oneOrTwo field could accept any valid JSON, significantly simplifying the table layout and improving flexibility in handling different object types.

@JonoPrest JonoPrest added the Enhancement New feature or request label Sep 25, 2024
@JonoPrest JonoPrest added the Feature label Sep 25, 2024 — with Linear
@JonoPrest
Copy link
Collaborator

Hey @pavlovdog,

I've added Jsonb as a feature request on our backlog. For the mean time to unblock you could use a string field and serialize your json.

It's unlikely we will support union types natively in the near future. Perhaps I can suggest you model your data with a nullable relationship field for both your entity One and Two. You can also model an algebraic enum (with a complex payload) just using an enum tag field.

For eg.

type One {
  id: ID!
  text: String!
}

type Two {
  id: ID!
  text: String!
  value: BigInt!
}

enum Tag {
  ONE
  TWO
}

type MyEntity {
  id: ID!
  tag: Tag!
  one: One
  two: Two
}

Then based on the tag you can look up the related entity, and only set the relevant payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Feature
Projects
None yet
Development

No branches or pull requests

2 participants