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

How to resolve a type from an id within a JSON field in a table #395

Closed
jasonwoodland opened this issue Dec 30, 2019 · 3 comments
Closed
Assignees
Labels

Comments

@jasonwoodland
Copy link
Contributor

Hey, I am trying to make the following query possible:

order(id: "T3JkZXI6MTk5OQ==") {
  items {
    quantity
    product {
      name
    }
  }
}

which would return something like:

"order": {
  "items": [
    {
      "quantity": 5,
      "product": {
        "name": "some product"
      }
    },
    {
      "quantity": 10,
      "product": {
        "name": "another product"
      }
    }
  ]
}

Seems rather simple, however, in my schema, my order table has a column named items of type json. Here's an example of what the items column on the order table would contain:

[
  {
    "quantity": 5,
    "productId": "UHJvZHVjdDox",
  },
  {
    "quantity": 10,
    "productId": "UHJvZHVjdDoyMDA="
  }
]

The items field on my OrderType is a GraphQLList(OrderItemType). Thus, my OrderItemType is a basic GraphQLObjectType with some scalar type fields which resolve as expected. However, one of the product field in my OrderItemType is a string containing a global ID of a ProductType. Currently I am only able to resolve the ID as a string, but am unsure of how to resolve it into a ProductType with join-monster? Is this even possible or should I ditch the JSON column in turn for an additional order_item table?

@nicoabie
Copy link
Contributor

nicoabie commented May 5, 2024

New maintainer here, were you able to find a solution?

@nicoabie
Copy link
Contributor

Here I demonstrate this could be done using SQLITE json_each function
PG also has this function

join-monster/join-monster-sscce#3

@jasonwoodland
Copy link
Contributor Author

Nice work! Thanks for making this example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants