Skip to content

How can I query a relation within Matrix via GraphQL #14546

Closed Answered by brandonkelly
tremby asked this question in Q&A
Discussion options

You must be logged in to vote

There’s not a great way to do this right now.

You could preload all the recipe + ingredient relations up front as part of your build pipeline, and reference that locally, if that’s an option.

Otherwise, if you really need to find related recipes on the fly, you could add a “Combined Products” relation field to the Recipes section, and set its value dynamically when recipes are saved.

use craft\base\Event;
use craft\elements\Entry;
use craft\events\ModelEvent;
use craft\fields\BaseRelationField;

Event::on(Entry::class, Entry::EVENT_AFTER_PROPAGATE, function(ModelEvent $event) {
    /** @var Entry $entry */
    $entry = $event->sender;

    // is this entry in the Recipes section?
    if ($e…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tremby
Comment options

@brandonkelly
Comment options

@tremby
Comment options

@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants