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.

How to filter by a key inside an object?

See original GitHub issue

Looking to filter by a key inside a nested JSON object. How would I accomplish that?

query

filter: {
  details: {
    selling_asset_code: "USD"
  }
}

data

{
  "data": {
    "allHistoryOperations": {
      "nodes": [
        {
          "transactionId": "33362562925989890",
          "details": {
            "price": "2.9973324",
            "amount": "149.1600010",
            "price_r": {
              "d": 100000000,
              "n": 299733237
            },
            "offer_id": 120736,
            "buying_asset_type": "native",
            "selling_asset_code": "USD",
            "selling_asset_type": "credit_alphanum4",
            "selling_asset_issuer": "GA7RXKBZOUA3FCUUS65JRLU5SZD3XBQUGRWL7NVQWU5QOXQW2LUZNBFZ"
          },
          "type": 3
        }
      ]
    }
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mattbretlcommented, Mar 11, 2019
1reaction
mattbretlcommented, Mar 10, 2019
createdb issue31
psql issue31
create schema p;
create table p.foo (id serial primary key, bar jsonb);
insert into p.foo (id, bar) values (2, '[{"a":1},{"b":2}]'::jsonb);
mkdir issue31
cd issue31
yarn add postgraphile
yarn add postgraphile-plugin-connection-filter
npx postgraphile --append-plugins postgraphile-plugin-connection-filter -c postgres://localhost:5432/issue31 --schema p
query {
  allFoos(filter: { bar: { contains: "[{\"a\":1}]" } }) {
    nodes {
      id
      bar
    }
  }
}
{
  "data": {
    "allFoos": {
      "nodes": [
        {
          "id": 2,
          "bar": "[{\"a\":1},{\"b\":2}]"
        }
      ]
    }
  }
}

That works as expected.

But with --dynamic-json, it fails:

npx postgraphile --append-plugins postgraile-plugin-connection-filter -c postgres://localhost:5432/issue31 --schema p --dynamic-json
query {
  allFoos(filter: { bar: { contains: [{a:1}] } }) {
    nodes {
      id
      bar
    }
  }
}
{
  "data": {
    "allFoos": {
      "nodes": []
    }
  }
}

The --dynamic-json support is part of the PostGraphile core lib, so hopefully @benjie can offer some insight?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Filter an Object by Key and Value in JavaScript
To filter an object by key-value, you can iterate over the object using Object.entries() const obj = { name: 'Luke Skywalker', title: 'Jedi ......
Read more >
How to Filter an Object by Key in JavaScript - Stack Abuse
After you've generated the keys, you may use filter() to loop over the existing values and return just those that meet the specified...
Read more >
Filter object properties by key in ES6 - Stack Overflow
Object.keys to list all properties in raw (the original data), then; Array.prototype.filter to select keys that are present in the allowed ...
Read more >
How to Filter an Javascript Object by Key? - STechies
In this article, we have discussed three different methods of filtering objects by keys, namely the Object.keys() method and filter() with reduce() methods ......
Read more >
How to Filter Keys of an Object with Lodash?
Lodash comes with the pickBy method that takes an object and a callback that lets us return the condition of the keys we...
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