Skip to content

GraphQL error with MySQL and FULL OUTER JOIN #2071

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

Closed
glogrus opened this issue Jun 16, 2020 · 2 comments · Fixed by #2104
Closed

GraphQL error with MySQL and FULL OUTER JOIN #2071

glogrus opened this issue Jun 16, 2020 · 2 comments · Fixed by #2104
Assignees

Comments

@glogrus
Copy link

glogrus commented Jun 16, 2020

Describe the bug
Page "/a/pages/visualize" has the following error:

[GraphQL error]: Message: select `pages`.`id` as `id`, `pages`.`path` as `path`, `title`, `pageLinks`.`path` as `link`, `pageLinks`.`localeCode` as `locale` from `pages` full outer join `pageLinks` on `pages`.`id` = `pageLinks`.`pageId` where `pages`.`localeCode` = 'en' - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'outer join `pageLinks` on `pages`.`id` = `pageLinks`.`pageId` where `pages`.`loc' at line 1, Location: [object Object], Path: pages,links

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/a/pages'
  2. Click on 'Visualize'
  3. See error

Expected behavior
Dendrogram representation of your pages.

Host Info (please complete the following information):

  • OS: CentOS 7
  • Wiki.js version: 2.4.107
  • Database engine: MySQL 8.0.20

Additional context
We don't have FULL JOINS on MySQL, but we can sure emulate them.

In file: server/graph/resolvers/pages.js replace code:

    /**
     * FETCH PAGE LINKS
     */
    async links (obj, args, context, info) {
      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
        })

with:

    /**
     * FETCH PAGE LINKS
     */
    async links (obj, args, context, info) {
      let results = []

      results = await WIKI.models.knex('pages')
        .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' })
        .leftOuterJoin('pageLinks', 'pages.id', 'pageLinks.pageId')
        .where({
          'pages.localeCode': args.locale
        }).unionAll(WIKI.models.knex('pages')
        .column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' })
        .rightOuterJoin('pageLinks', 'pages.id', 'pageLinks.pageId')
        .where({
          'pages.localeCode': args.locale
        }))
@regevbr
Copy link
Contributor

regevbr commented Jun 24, 2020

duplicate of #1715
Will try to make a PR later today

@regevbr
Copy link
Contributor

regevbr commented Jun 24, 2020

Also doesn't work with sqlite.
The proposed solution will not work on sqlite as right join is not supported.
I will try to follow https://www.sqlitetutorial.net/sqlite-full-outer-join/ in the fix

regevbr added a commit to PruvoNet/wiki that referenced this issue Jun 24, 2020
regevbr added a commit to PruvoNet/wiki that referenced this issue Jun 24, 2020
NGPixel pushed a commit that referenced this issue Jun 24, 2020
* fix: GraphQL error with MySQL and FULL OUTER JOIN #2071
jionggyu pushed a commit to jionggyu/wiki-2.5.302-patch that referenced this issue Jul 9, 2024
* fix: GraphQL error with MySQL and FULL OUTER JOIN requarks#2071
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

Successfully merging a pull request may close this issue.

3 participants