mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

Passing `where:` in-place, without query variable #709

Closed docelic closed 2 years ago

docelic commented 2 years ago

Hello,

When I pass where: condition as query variable, everything works as expected. E.g.:

# Query itself:
query($where:SequelizeJSON) {
    listOfThings(where: $where) {
      id
      name
  }
}

# Query var:
{
  "where": "{ \"name\": { \"like\": \"%c%\" }}"
}

But when passing the condition in-place as a string, like where: "{ \"name\": { ... } }", then options.where gets parsed incorrectly and results in it being split on every character:

{
  '0': '{',
  '1': ' ',
  '2': '"',
  '3': 'n',
  '4': 'a',
  '5': 'm',
  '6': 'e',
  ...

What's the reason for this, and can the where condition be passed in-place in any way?

Thanks.

mickhansen commented 2 years ago

Not sure why it operates differently when passed in the query. The where helper was a contribution, you're welcome to submit a PR with a fix. Generally I don't like open ended arguments like where for GraphQL.

docelic commented 2 years ago

Hm, while it doesn't accept strings, it does accept hashes directly, like:

listOfThings( where: { name: { like: "%test%" }})

So I believe there's nothing left to be done here. Thanks.