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

Craft 3.1.19 breaks entriesConnection, et al. #248

Closed
timkelty opened this issue Mar 20, 2019 · 23 comments · Fixed by #249
Closed

Craft 3.1.19 breaks entriesConnection, et al. #248

timkelty opened this issue Mar 20, 2019 · 23 comments · Fixed by #249

Comments

@timkelty
Copy link
Contributor

timkelty commented Mar 20, 2019

Seems odd for a patch release, but queries with entriesConnection / tagsConnection / categoriesConnection started breaking upon upgrading craftcms/cms from 3.1.18 => 3.1.19.

I locked the version down and confirmed it works if I go back to 3.1.18.

Given query:

query {
  categoriesConnection(limit:1) {
    edges {
      node {
        id
      }
    }
  }
}

on craftcms/[email protected]:

{
  "errors": [
    {
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "entriesConnection"
      ]
    }
  ],
  "data": {
    "entiresConnection": null
  }
}

on craftcms/[email protected]:

{
  "data": {
    "entriesConnection": {
      "edges": [
        {
          "node": {
            "id": 18881
          }
        }
      ]
    }
  }
}

I haven't peeked at the source of the 3.1.19 release yet, but maybe @brandonkelly might be able to shine some light.

@timkelty timkelty changed the title Craft 3.1.19 breaks entriesConnection Craft 3.1.19 breaks entriesConnection, et al. Mar 20, 2019
@timkelty
Copy link
Contributor Author

I've tried this with markhuot/[email protected] and dev-master with the same result.

@brandonkelly
Copy link
Collaborator

3.1.19 was a pretty tame release. Just looked through it and not really sure what could be messing with CraftQL. Happy to look into it further if anyone has any ideas.

@timkelty
Copy link
Contributor Author

Looking through the release notes, my only guess is something to do with the pagination changes, as that is exposed through these element connections. (‘pageInfo’)

Hopefully will have some time to look into it this week.

@timkelty
Copy link
Contributor Author

@brandonkelly hmmm does appear pagination related…the actual thrown exception:

2019-03-20 07:32:28 [-][-][-][error][yii\base\UnknownPropertyException] yii\base\UnknownPropertyException: Setting unknown property: craft\web\twig\variables\Paginate::limit in /app/vendor/composer/yiisoft/yii2/base/BaseObject.php:163

@brandonkelly
Copy link
Collaborator

@timkelty What is the stack trace?

@timkelty
Copy link
Contributor Author

nothing helpful - still digging: 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/exception.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/yiisoft/yii2/views/errorHandler/callStackItem.php 2019-03-20 07:32:28 [-][-][-][trace][yii\base\View::renderFile] Rendering view file: /app/vendor/composer/y

@timkelty
Copy link
Contributor Author

timkelty commented Mar 20, 2019

@brandonkelly Looking at the CrafQL code, I suspect its coming from \craft\helpers\Template::paginateCriteria($criteria):

craftql/src/Types/Query.php

Lines 113 to 129 in e4b5a43

$this->addField('entriesConnection')
->name('entriesConnection')
->type(EntryConnection::class)
->use(new EntryQueryArguments)
->resolve(function ($root, $args, $context, $info) {
$criteria = $this->getRequest()->entries(\craft\elements\Entry::find(), $root, $args, $context, $info);
list($pageInfo, $entries) = \craft\helpers\Template::paginateCriteria($criteria);
$pageInfo->limit = @$args['limit'] ?: 100;
return [
'totalCount' => $pageInfo->total,
'pageInfo' => $pageInfo,
'edges' => $entries,
'criteria' => $criteria,
'args' => $args,
];
});

@brandonkelly
Copy link
Collaborator

Huh… $pageInfo is a craft\web\twig\variables\Paginate object there, and that has never had a $limit property.

Here’s all of the changes made to that class in 2.0.19:

craftcms/cms@3.1.18...3.1.19#diff-d85eed56af7711fc3697dcae8e501448

So maybe this is just because we now have it extend yii\base\BaseObject, which is maybe more strict about setting unknown properties than vanilla classes are.

@markhuot Do you recall what the point of this line is?

$pageInfo->limit = @$args['limit'] ?: 100;

@timkelty
Copy link
Contributor Author

Yeah - seems like the intention is for the limit (default 100) to be on the $criteria, not $pageInfo.

brandonkelly added a commit to brandonkelly/craftql that referenced this issue Mar 20, 2019
Fixes markhuot#248 and pagination in general
@brandonkelly
Copy link
Collaborator

@markhuot Just submitted #249 to fix this, but I’m guessing all that is going to do is start limiting the results where previously they weren’t being limited at all, since limit wasn’t getting set on the element query like it would need to. So probably worth testing and making sure pagination works correctly.

@timkelty
Copy link
Contributor Author

Thanks @brandonkelly!

@danireginatto
Copy link

+1 have a solution for this problem?

@swthate
Copy link

swthate commented Mar 26, 2019

I'm interested in the progress of this as well. I'll have to hold some projects back to 3.1.18 until there is a fix as they rely on CraftQL 2 beta.

@markhuot
Copy link
Owner

Will be reviewing this, this week, to get a release cut.

@danireginatto
Copy link

Will be reviewing this, this week, to get a release cut.

Mark, Can you tell us when we can test? My system is broke.

@brandonkelly
Copy link
Collaborator

In the meantime you should be able to get it working (and help test) by switching over to my PR branch.

To do that, add my repo to the repositories config in composer.json, and change your markhuot/craftql requirement to dev-248-fix:

{
  "require": {
    "markhuot/craftql": "dev-248-fix",
    "...": "..."
  },
  "repositories": [
    {"type": "vcs", "url": "https://github.com/brandonkelly/craftql"}
  ],
  "...": "..."
}

Then run composer update.

@narration-sd
Copy link
Contributor

That's a great contributive move,, @brandonkelly -- and a great method to keep in mind, seeing how it works....

@nc2-jordansmith
Copy link

Tested the dev-248-fix on Craft v3.1.19 and v3.1.20.1 and it works for me. I'll still need to wait for the release version for my team to use it, but thanks, @brandonkelly!

@dineufeld
Copy link

When to expect with an update? I have I an external API managed by CraftQL and I don't have an access to make downgrade of the craft version on the server.

@seamofreality
Copy link

Tested the dev-248-fix too (on Craft 3.1.20.1), got this error:

{
  "error": "Argument 1 passed to craft\\db\\Paginator::__construct() must implement interface yii\\db\\QueryInterface, array given, called in /usr/share/nginx/vendor/markhuot/craftql/src/Types/CategoryInterface.php on line 33"
}

Trying to query categories and their child entries:

{
  categories(group: teamCategory) {
    id
    title
    uri
    childrenConnection {
      edges {
        node {
          id
        }
      }
    }
  }
}

brandonkelly added a commit to brandonkelly/craftql that referenced this issue Apr 9, 2019
@brandonkelly
Copy link
Collaborator

@seamofreality Good catch. By the looks of it, a similar error would occur on the main release as well, pre-Craft 3.1.19. Just fixed it in my PR though. Try running composer clear-cache and then composer update.

@seamofreality
Copy link

@brandonkelly Thanks a dozen for the quick fix, it seems to work now!

markhuot added a commit to brandonkelly/craftql that referenced this issue Apr 15, 2019
@markhuot
Copy link
Owner

Release 1.3.2 should fix the issue based on the Paignator changes.

seamofreality pushed a commit to djfarly/craftql that referenced this issue Jul 3, 2019
Fixes markhuot#248 and pagination in general
seamofreality pushed a commit to djfarly/craftql that referenced this issue Jul 3, 2019
seamofreality pushed a commit to djfarly/craftql that referenced this issue Jul 3, 2019
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.

9 participants