From 33a9d5774cbf855c6c783e018443e49b430ea0df Mon Sep 17 00:00:00 2001 From: Regev Brody Date: Thu, 25 Jun 2020 01:51:21 +0300 Subject: [PATCH] fix: GraphQL error with MySQL and FULL OUTER JOIN (#2104) * fix: GraphQL error with MySQL and FULL OUTER JOIN #2071 --- server/graph/resolvers/page.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/server/graph/resolvers/page.js b/server/graph/resolvers/page.js index 53275ff7..b9db3793 100644 --- a/server/graph/resolvers/page.js +++ b/server/graph/resolvers/page.js @@ -246,14 +246,31 @@ module.exports = { * FETCH PAGE LINKS */ async links (obj, args, context, info) { - let results = [] + let results; - results = await WIKI.models.knex('pages') - .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' }) - .fullOuterJoin('pageLinks', 'pages.id', 'pageLinks.pageId') - .where({ - 'pages.localeCode': args.locale - }) + if (WIKI.config.db.type === 'mysql' || WIKI.config.db.type === 'mariadb' || WIKI.config.db.type === 'sqlite') { + results = await WIKI.models.knex('pages') + .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' }) + .leftJoin('pageLinks', 'pages.id', 'pageLinks.pageId') + .where({ + 'pages.localeCode': args.locale + }) + .unionAll( + WIKI.models.knex('pageLinks') + .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' }) + .leftJoin('pages', 'pageLinks.pageId', 'pages.id') + .where({ + 'pages.localeCode': args.locale + }) + ) + } else { + results = await WIKI.models.knex('pages') + .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' }) + .fullOuterJoin('pageLinks', 'pages.id', 'pageLinks.pageId') + .where({ + 'pages.localeCode': args.locale + }) + } return _.reduce(results, (result, val) => { // -> Check if user has access to source and linked page