question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQL Query JSON?

See original GitHub issue

It’d be really cool if we could declare a field as JSON/B and query it per usual. My reasons for thinking this is that sifting through 50 columns in a table for misc stuff—or having 10 tables all revolving around the same concept—seems messy and hard to navigate.

In contrast, dumping things that are related to a concept, but not big enough to warrant their own table, might clean a db up. For instance, a User might have a profile with some addresses, names, and such in it… A User might also have a bunch of stuff related to auth (e.g. tokens, providers, roles, etc.). If you break those out into their own columns on the User table, you end up with 50 columns. If you break them out to their own tables, you end up stitching together all those tables with relationships.

Open to discussion/suggestions/critique, but the generic query syntax might look like this:

(https://www.db-fiddle.com/f/UsVwfCin7LFLZbAuW691G/2)

{
  user {
    profile {
      name
    }
  }
}

And where syntax might look like this:

{
  user {
    profile(where: {
      addresses: {
        _contains: {
          type: "billing"
        }
      }
    }) {
      name
    }
  }
}

So I suppose arrays could do _contains where the param is part of an object?

Feel free to poke holes in this. No rush. I’m slightly concerned what performance would be, and if perf is fine, then nailing the syntax might be tricky if there isn’t some GraphQL spec for it already.


Resources:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ethanabrookscommented, Jul 8, 2021

Is there a way to use the postgres ->> and #>> operators in query filters, e.g.

{
  user {
    profile(where: {
      addresses: {
        path: "->>'street'",
        _like: "Pennsylvania %"
      }
    }) {
      name
    }
  }
}
2reactions
hgiasaccommented, May 22, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Serving over HTTP - GraphQL
Query variables can be sent as a JSON-encoded string in an additional query parameter called variables . If the query contains several named...
Read more >
GraphQL to JSON Body Converter - Data Fetcher
Converting a GraphQL query to a JSON body is simple. First, we remove new lines/ extra spaces from the GraphQL query. Then we...
Read more >
graphql query to json query - Stack Overflow
Given this GraphQL example, how can I in Javascript do a similar request with JSON? Using GraphQL the query in the example is:...
Read more >
json-to-graphql-query - npm
This is a simple module that takes a JavaScript object and turns it into a GraphQL query to be sent to a GraphQL...
Read more >
vkolgi/json-to-graphql-query - GitHub
json -to-graphql-query ... This is a simple module that takes a JavaScript object and turns it into a GraphQL query to be sent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found