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

Bugfix: $sort field set incorrectly in GET_LIST handler #84

Closed
nicholasnelson opened this issue Oct 24, 2018 · 0 comments
Closed

Bugfix: $sort field set incorrectly in GET_LIST handler #84

nicholasnelson opened this issue Oct 24, 2018 · 0 comments

Comments

@nicholasnelson
Copy link
Contributor

In testing Websocket compatibility, I've found the following issue.

Feathers documentation shows the query format for $sort in GET_LIST as follows:

// Find the 10 newest messages
app.service('messages').find({
  query: {
    $limit: 10,
    $sort: {
      createdAt: -1
    }
  }
});

ra-data-feathers currently provides the $sort param like this:

query: {
  '$sort[createdAt]': '-1'
}

This works for the REST transport, but not for Websocket.

I suspect this is because the REST transport on the server side parses $sort[createdAt]: '-1' to $sort: { createdAt: '-1' } when the query string is parsed. When Websocket is being used, the query is not parsed (because it is sent directly as an object rather than a string).

For example in my project which is backed by Sequelize, this results in a SQL query like ... WHERE '$sort[createdAt]' = '-1' ... which then gives an error about the field '$sort[createdAt]' not existing.

Updating GET_LIST to set the $sort parameter as in the Feathers documentation example above should resolve this issue.

nicholasnelson pushed a commit to nicholasnelson/ra-data-feathers that referenced this issue Oct 24, 2018
Change format of the query object in GET_LIST

From:
```js
query: {
  '$sort[createdAt]': '-1'
}
```

To:
```js
query: {
  $sort': {
    'createdAt': '-1'
  }
}
```

Fixes bug when using Feathers Websocket transport

Closes josx#84
nicholasnelson pushed a commit to nicholasnelson/ra-data-feathers that referenced this issue Oct 24, 2018
Update tests to reflect needed change

Change format of the query object in GET_LIST

From:
```js
query: {
  '$sort[createdAt]': '-1'
}
```

To:
```js
query: {
  $sort': {
    'createdAt': '-1'
  }
}
```

Fixes bug when using Feathers Websocket transport

Closes josx#84
@josx josx closed this as completed in #85 Oct 24, 2018
josx pushed a commit that referenced this issue Oct 24, 2018
Update tests to reflect needed change

Change format of the query object in GET_LIST

From:
```js
query: {
  '$sort[createdAt]': '-1'
}
```

To:
```js
query: {
  $sort': {
    'createdAt': '-1'
  }
}
```

Fixes bug when using Feathers Websocket transport

Closes #84
nicholasnelson pushed a commit to nicholasnelson/ra-data-feathers that referenced this issue Feb 12, 2019
For an unknown reason, query params were being flattened in GET_LIST.
This resulted in requests with nested query params failing.
This commit removes the flattening.

Fixes josx#84
nicholasnelson pushed a commit to nicholasnelson/ra-data-feathers that referenced this issue Feb 12, 2019
For an unknown reason, query params were being flattened in GET_LIST.
This resulted in requests with nested query params failing.
This commit removes the flattening.

Fixes josx#84
josx pushed a commit that referenced this issue Feb 12, 2019
For an unknown reason, query params were being flattened in GET_LIST.
This resulted in requests with nested query params failing.
This commit removes the flattening.

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

No branches or pull requests

1 participant