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

fix(graphql): filter out orphaned relationships #7363

Merged
merged 1 commit into from Aug 7, 2020

Conversation

admosity
Copy link
Contributor

@admosity admosity commented Aug 7, 2020

Description of what you did:

We have entities that reference another entity that could be deleted. For performance reasons, any entity that is orphaned is cleaned at a later time, but this is breaking our graphql aggregation queries. This PR adds a simple existence filter on the _id field that exists when null as well. Maybe it might also be beneficial to allow grouping by null to check orphaned relationships?

Output from a log above converting the result to an array:

image

image

Output from the graphql query:

{
  "errors": [
    {
      "message": "Cannot read property 'toString' of null",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "entriesConnection",
        "groupBy",
        "release"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot read property 'toString' of null",
            "    at /Users/me/git/proj/redacted/node_modules/strapi-plugin-graphql/services/build-aggregation.js:220:22",
            "    at arrayMap (/Users/me/git/proj/redacted/node_modules/strapi-plugin-graphql/node_modules/lodash/lodash.js:639:23)",
            "    at Function.map (/Users/me/git/proj/redacted/node_modules/strapi-plugin-graphql/node_modules/lodash/lodash.js:9554:14)",
            "    at preProcessGroupByData (/Users/me/git/proj/redacted/node_modules/strapi-plugin-graphql/services/build-aggregation.js:217:12)",
            "    at resolver (/Users/me/git/proj/redacted/node_modules/strapi-plugin-graphql/services/build-aggregation.js:274:14)",
            "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
          ]
        }
      }
    }
  ],
  "data": {
    "entriesConnection": {
      "groupBy": {
        "release": null
      }
    }
  }
}

Signed-off-by: Adam Lee <admosity@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #7363 into master will increase coverage by 0.05%.
The diff coverage is 48.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7363      +/-   ##
==========================================
+ Coverage   26.17%   26.22%   +0.05%     
==========================================
  Files        1130     1131       +1     
  Lines       15415    15433      +18     
  Branches     2439     2443       +4     
==========================================
+ Hits         4035     4048      +13     
- Misses       9561     9565       +4     
- Partials     1819     1820       +1     
Flag Coverage Δ
#front 18.26% <0.00%> (-0.01%) ⬇️
#unit 53.14% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...s/strapi-admin/admin/src/containers/Admin/index.js 63.82% <ø> (ø)
...admin/admin/src/containers/Roles/EditPage/index.js 2.77% <0.00%> (-0.80%) ⬇️
...admin/admin/src/containers/Roles/ListPage/index.js 0.00% <0.00%> (ø)
...ermissions/admin/src/components/PopUpForm/index.js 0.00% <0.00%> (ø)
packages/strapi-admin/services/metrics.js 100.00% <100.00%> (ø)
packages/strapi-admin/services/role.js 94.11% <100.00%> (+0.14%) ⬆️
packages/strapi-admin/services/user.js 82.56% <100.00%> (+0.66%) ⬆️
packages/strapi/lib/services/metrics/sender.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7113f7f...5998f0d. Read the comment docs.

@alexandrebodin alexandrebodin added this to the 3.1.4 milestone Aug 7, 2020
@alexandrebodin alexandrebodin added source: plugin:graphql Source is plugin/graphql package issue: enhancement Issue suggesting an enhancement to an existing feature labels Aug 7, 2020
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: plugin:graphql Source is plugin/graphql package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants