Trying to understand how graphql plugin works

Hello. I’m pretty new to Graph QL, and I’ve been looking into how Strapi handles the n+1 problem of loading data. I set the backend database debug: true, and I ran the following graphql query on the Foodadvisor application:

GraphQL query

query {
  restaurants(limit: 12) {
    id
    description
    district
    cover {
      url
    }
    category {
      name
    }
    name
    note
    price
    reviews {
      note
      content
    }
  }
  restaurantsConnection {
    aggregate {
      count
    }
  }
  categories {
    id
    name
  }
}

Here’s part of the debug logs I see. Please keep in mind this is only for the restaurants part of the query:

Logs

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '26914f81-24ad-4a92-92cd-1b40a0770cd2',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ee6f0427-bf2f-4140-9ba4-c78344d0fd99',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
...

And the same thing for the views part of the query:

Logs

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '1' ],
  __knexQueryUid: '98410d14-8716-4c63-9779-a6be3b36b66d',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '2' ],
  __knexQueryUid: '99811e9c-8eb1-45de-b4cd-5224c52fcad9',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '3' ],
  __knexQueryUid: 'bd8da4e2-a5f1-45ef-adf2-f72b3a1a9b6f',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '4' ],
  __knexQueryUid: 'fd15a99a-4b1d-4333-9ceb-fa5e4c9661c9',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '5' ],
  __knexQueryUid: '59ab6f1f-987b-4250-b0b8-127f8d9df48f',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}

And the same thing for the categories part of the query:

Logs

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '1' ],
  __knexQueryUid: '483c505a-bcb1-4f03-9b1a-97369bf6d3a5',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '6' ],
  __knexQueryUid: '78004bc9-f200-427b-bc65-db490016c467',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '8' ],
  __knexQueryUid: 'bf2bed14-71af-4663-9576-a279a1fff30f',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '9' ],
  __knexQueryUid: '63172f4a-e230-4162-87a2-b608d981042d',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '12' ],
  __knexQueryUid: 'd950d850-09cc-43eb-9b0d-335117447ea7',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 8, 1 ],
  __knexQueryUid: '9481bbff-878c-4f17-8495-7da77fb395f3',
  sql: 'select avg(`note`) as `note` from `reviews` where `restaurant` = ? limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 9, 1 ],
  __knexQueryUid: '7d389a56-ba72-4a96-b6c4-a40863242731',
  sql: 'select avg(`note`) as `note` from `reviews` where `restaurant` = ? limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 10, 1 ],
  __knexQueryUid: '548b310d-0575-4732-b5a2-abcfeeefa849',
  sql: 'select avg(`note`) as `note` from `reviews` where `restaurant` = ? limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 11, 1 ],
  __knexQueryUid: '87354ad4-f7a5-498d-b55d-adc1dcb83e74',
  sql: 'select avg(`note`) as `note` from `reviews` where `restaurant` = ? limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 12, 1 ],
  __knexQueryUid: '7c4eb45d-76c6-4565-a864-d35274036793',
  sql: 'select avg(`note`) as `note` from `reviews` where `restaurant` = ? limit ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [
     1,  2,  3,   4,  5,  6,  7,  8,  9, 10, 11, 12,
    13, 14, 15,  16, 17, 18, 19, 20, 21, 22, 23, 24,
    25, 26, 27,  28, 29, 30, 31, 32, 33, 34, 35, 36,
    37, 38, 39,  40, 41, 42, 43, 44, 45, 46, 47, 48,
    49, 50, 51,  52, 53, 54, 55, 56, 57, 58, 59, 60,
    61, 62, 63,  64, 65, 66, 67, 68, 69, 70, 71, 72,
    73, 74, 75,  76, 77, 78, 79, 80, 81, 82, 83, 84,
    85, 86, 87,  88, 89, 90, 91, 92, 93, 94, 95, 96,
    97, 98, 99, 100,
    ... 16 more items
  ],
  __knexQueryUid: '45badb32-9044-4bf2-a77a-e45fd464657a',
  sql: 'select distinct `upload_file`.* from `upload_file` where `upload_file`.`id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) order by `created_at` desc'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [
     65,  66,  70,  72,  74,  75,  76,  78,  80,  81,  83,
     86,  88,  89,  92,  94,  98, 101, 104, 105, 109, 113,
    116, 118, 119, 121, 124, 125, 128,  67,  71,  73,  77,
     79,  82,  84,  87,  90,  93,  95,  99, 102, 106, 110,
    114, 115, 120, 122, 126,  68,  85,  91,  96, 100, 103,
    107, 111, 117, 123, 127,  69,  97, 108, 112
  ],
  __knexQueryUid: '8a02fd3d-2606-47b9-93f5-8c9c731581f8',
  sql: 'select `components_opening_hours`.* from `components_opening_hours` where `id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '29f1be7b-e0ce-4176-812b-c792657b9c80',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '901a1bf2-115b-4cc5-9a27-08f95a1084da',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '0c8aa798-7538-4c10-9d36-2f40a22633cb',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'd53396a3-0763-400f-8414-ae540a925f29',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '609dca01-5b18-462f-bd41-3a77488ee602',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'a0a7943f-e407-42e2-be60-aa2d0531922a',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'bb237933-01c1-487b-bd84-5a3d56d6756c',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '322f78be-df12-46cc-a75c-199167630fd3',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '38fa8a78-976c-4f08-a56f-bba3449e6f70',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '3bbf708d-3a8a-41f8-a5ac-389d24f0d5b2',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '8125778d-5994-4213-b144-f3a5fab3fc3e',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'af0e8f75-e7c3-4cdb-895d-4e6353732037',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'f528a101-4d79-4362-a62d-95bc54f036c5',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '067a798b-8ba5-46c5-9426-5c35b7eea83b',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '4220bd42-0ead-4ce2-b923-54664906cf30',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ba36567a-97c0-43d9-b0d0-38de765a1fb4',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '41a5a79f-c622-4192-a1ad-e811f3be9f6f',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'bfa55640-bd47-4a28-9259-5441322e7588',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '210e0837-9921-453b-a55f-6dab525cd94e',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'f715e338-2a1b-441c-a9a1-d22b5b08d0fb',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '78975f52-cf51-46b9-924d-d2316f7d03f0',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '72c2ab9b-4250-4f8a-ab04-26f9259a1958',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'c8b8825f-871e-4e4e-9805-082718f2503c',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'd0d403c7-0d40-406a-aadd-0feaf8305bca',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '0e13d0c0-8ca3-481b-8e18-1381cf4cb65f',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '277125d3-165c-4f90-98f8-3101a0711956',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '6c393c65-adf6-4c7b-8211-7a53d0b6e771',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '125b7b8f-93c7-4e0f-bff7-7e7697b9ab7d',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '39d0cbda-3c02-4f5a-8c18-95528e2522b4',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '3b850097-bfe7-4d45-b9d9-811c99afd623',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'e92368d6-8c47-41b0-9827-584ec81ceda1',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '3819463b-c840-4fda-8ba3-aaed1e056e65',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '5698afc5-ed00-4f9b-bdf8-9cc290a65d48',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '3a841748-b653-4552-8fb3-090536569fdc',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'd97228cd-2f77-4460-aa5b-e9659b70791e',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '5133d2ae-346f-45e3-af62-e4c367fca35d',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '813bb450-6029-45a6-bbb3-140e5c0d8cbe',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '85ae499f-79e6-4c6a-b381-9be62b35377b',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '2c2b8721-331d-49ff-9bba-bf94fc082905',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '102b29c8-37dd-489f-b268-7a93a9fa5c28',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '8fde7628-12ce-47cc-b693-53fae3868815',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '4d6db60f-549c-44d2-9dda-c8b75f230111',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '26914f81-24ad-4a92-92cd-1b40a0770cd2',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '513caaf9-749e-4cb5-b9d0-3e675ba75c2d',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ffea4d6d-5049-4d48-a1fc-1f488dc02c4a',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ed37d801-fd1d-45e4-9b45-63768a7a3fd0',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '0f2eed1e-7917-4859-a54c-84763e66fdcf',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ba916499-3e49-4c65-b2aa-eabfdd3d0bfe',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '7f7814ea-013e-4810-b27e-40ad65c19adb',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '6525462f-4957-4400-a5af-f7aa43f63aeb',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'e2a3465d-43e5-446f-8c7d-37a1b04c7edc',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '0c889c2a-e681-43c8-94d7-fc3604e02feb',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'ee6f0427-bf2f-4140-9ba4-c78344d0fd99',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '03c18040-ce0e-405e-8307-3a0447a7048b',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '334a0855-f171-4bee-a2f1-1b9b37307000',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: 'c276e1c9-d852-446e-bd7f-205aef397a5d',
  sql: 'select distinct `likes`.* from `likes` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '19df4d02-a501-4110-a633-7885ef57ae81',
  sql: 'select distinct `users-permissions_user`.* from `users-permissions_user` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '675cd881-1690-47aa-ad14-855ce1d65bdb',
  sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '157a9af9-89d9-4765-8f07-eb0547d5676f',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 0 ],
  __knexQueryUid: '6f2ce094-5819-4186-90be-050b15411b5b',
  sql: 'select distinct `strapi_administrator`.* from `strapi_administrator` where 1 = ?'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '1' ],
  __knexQueryUid: '483c505a-bcb1-4f03-9b1a-97369bf6d3a5',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '6' ],
  __knexQueryUid: '78004bc9-f200-427b-bc65-db490016c467',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '8' ],
  __knexQueryUid: 'bf2bed14-71af-4663-9576-a279a1fff30f',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '9' ],
  __knexQueryUid: '63172f4a-e230-4162-87a2-b608d981042d',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '12' ],
  __knexQueryUid: 'd950d850-09cc-43eb-9b0d-335117447ea7',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '13' ],
  __knexQueryUid: '1fdd8a51-4d7f-404c-b512-9bb0cd4bd078',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '14' ],
  __knexQueryUid: 'f535b335-4146-4dad-af86-6fba60a9b444',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '10' ],
  __knexQueryUid: 'c4ee7022-e95b-4998-b370-76c41f240edd',
  sql: 'select distinct `categories`.* from `categories` where `categories`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '1' ],
  __knexQueryUid: '98410d14-8716-4c63-9779-a6be3b36b66d',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '2' ],
  __knexQueryUid: '99811e9c-8eb1-45de-b4cd-5224c52fcad9',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '3' ],
  __knexQueryUid: 'bd8da4e2-a5f1-45ef-adf2-f72b3a1a9b6f',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '4' ],
  __knexQueryUid: 'fd15a99a-4b1d-4333-9ceb-fa5e4c9661c9',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '5' ],
  __knexQueryUid: '59ab6f1f-987b-4250-b0b8-127f8d9df48f',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '6' ],
  __knexQueryUid: 'a72dd187-a7a6-414d-8d85-9eef46390b26',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '7' ],
  __knexQueryUid: 'f71ae3ca-d10f-4a29-8891-bbf2947baabd',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '8' ],
  __knexQueryUid: 'f436cecf-672c-4366-b43b-2fc6f45b0600',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '9' ],
  __knexQueryUid: 'fad32e0c-a484-4ee6-9ab4-82a4d5e436ed',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '10' ],
  __knexQueryUid: 'f852b6d3-bcbd-46da-ace3-725a92f55d9a',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '11' ],
  __knexQueryUid: 'e01ef6f7-73f1-4e6c-b88b-8c43f2c13149',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '12' ],
  __knexQueryUid: 'a373630f-151c-46ae-8a01-e0a9fa111db8',
  sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 1 ],
  __knexQueryUid: '8c02a128-5b94-4807-9b95-08fef7f03625',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 2 ],
  __knexQueryUid: '5aec981c-7e13-4508-8964-6482499ca735',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 3 ],
  __knexQueryUid: 'e4932c32-1ca0-4d27-bc15-488e6469e425',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 4 ],
  __knexQueryUid: 'a5e2a4d1-cc5c-457d-a106-0864ea3b152d',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 5 ],
  __knexQueryUid: '752310fe-ee55-4f17-b363-9665eae31c20',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 6 ],
  __knexQueryUid: '18ee0569-0d77-44d2-8920-be9ef7bd1860',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 7 ],
  __knexQueryUid: 'a9673a0f-e0a7-4306-8d25-3a266db0abac',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 9 ],
  __knexQueryUid: '5ddf848c-eccd-478f-8981-ec6ef2f2572e',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 10 ],
  __knexQueryUid: 'a7042eb5-0cec-4109-a4af-b138c4b511ae',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 11 ],
  __knexQueryUid: '9f18b66b-bc37-4ace-8b8e-877966ad61c6',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 12 ],
  __knexQueryUid: '3953a8b7-e9ea-47c9-954c-070a5fc629bf',
  sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'
}

Looks like strapi makes a database query for every restaurant fetched from the database.

Also, please notice all the unrelated queries about components, likes, opening hours, avg notes etc.

I would love to find out if there’s any way to improve this, or if this is a problem that can’t be solved.

Just want to learn more about how this system works.

Thanks !

@bahdcoder Thank you for the detailed info, your are correct in that we currently have optimizations to be made on the GraphQL plugin. This is a popular issue that we are discussing internally right now and will absolutely be a focus going forward.

Related tracking issue on GitHub