Skip to content

GraphQL sorting on manyWay relation does not do anything #8099

@derrickmehaffy

Description

@derrickmehaffy

Describe the bug
Applying a sort: field:direction does not work in a GraphQL query that is attempting to sort on a manyWay relation.

Steps to reproduce the behavior

  1. Create two models: Article and Comment
  2. Create a many way relation between them where "Article has many Comments"
  3. Using the playground, attempt to query all articles and try to sort the comments by one of the fields in any direction
  4. See no change has occurred and the sort isn't passed into the Knex Query

Expected behavior
A sort param is passed into Knex and thus the result is sorted

Screenshots

image

image

Code snippets

GraphQL Query

query {
  articles {
    id
    title
    body
    comments (sort: "text:asc"){
      id
      text
    }
  }
}

Article Model

{
  "kind": "collectionType",
  "collectionName": "articles",
  "info": {
    "name": "article"
  },
  "options": {
    "increments": true,
    "timestamps": true
  },
  "attributes": {
    "title": {
      "type": "string"
    },
    "body": {
      "type": "richtext"
    },
    "comments": {
      "collection": "comment"
    }
  }
}

Comment Model

{
  "kind": "collectionType",
  "collectionName": "comments",
  "info": {
    "name": "comment"
  },
  "options": {
    "increments": true,
    "timestamps": true
  },
  "attributes": {
    "text": {
      "type": "string"
    }
  }
}

System

  • Node.js version: 12.18.3
  • NPM version: 6.14.6
  • Strapi version: 3.1.6
  • Database: SQLite
  • Operating system: Linux Mint 20 - ulyana (Ubuntu 20.04)

Additional context

Knex log for sort by text:asc

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 100 ],
  __knexQueryUid: '8b7c8ac2-6a72-4eaa-88aa-466fa5588dd1',
  sql: 'select `articles`.* from `articles` limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 1 ],
  __knexQueryUid: '68705428-42f4-45e8-9c1b-425ec6d7061c',
  sql: 'select distinct `comments`.*, `articles__comments`.`article_id` as `_pivot_article_id`, `articles__comments`.`comment_id` as `_pivot_comment_id` from `comments` inner join `articles__comments` on `articles__comments`.`comment_id` = `comments`.`id` where `articles__comments`.`article_id` in (?)'
}

Knex log for sort by text:desc

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 100 ],
  __knexQueryUid: '6110d263-d52f-452a-b49e-99f599677dc6',
  sql: 'select `articles`.* from `articles` limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 1 ],
  __knexQueryUid: '6ef13c28-01d1-4bc6-b057-7a8ec32bbb97',
  sql: 'select distinct `comments`.*, `articles__comments`.`article_id` as `_pivot_article_id`, `articles__comments`.`comment_id` as `_pivot_comment_id` from `comments` inner join `articles__comments` on `articles__comments`.`comment_id` = `comments`.`id` where `articles__comments`.`article_id` in (?)'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: core:databaseSource is core/database packagesource: plugin:graphqlSource is plugin/graphql packagestatus: confirmedConfirmed by a Strapi Team member or multiple community members

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions