The orRelatedToEntries gql argument #17820
-
|
Hey, On a lot my graphql projects, I need to use an Usually I create my own Does that make sens or am I doing something wrong ? Event::on(
Gql::class,
Gql::EVENT_REGISTER_GQL_QUERIES,
function(RegisterGqlQueriesEvent $event) {
$orRelatedToEntriesArgs = [
'orRelatedToEntries' => [
'name' => 'orRelatedToEntries',
'type' => fn() => Type::listOf(EntryRelation::getType()),
'description' => 'Narrows the query results to elements that are related the entry list defined with this argument.',
],
];
$event->queries['entries']['args'] = array_merge(
$event->queries['entries']['args'],
$orRelatedToEntriesArgs
);
$event->queries['entryCount']['args'] = array_merge(
$event->queries['entryCount']['args'],
$orRelatedToEntriesArgs
);
}
);
Event::on(
ArgumentManager::class,
ArgumentManager::EVENT_DEFINE_GQL_ARGUMENT_HANDLERS,
function(RegisterGqlArgumentHandlersEvent $event) {
$event->handlers['orRelatedToEntries'] = OrRelatedEntries::class;
}
); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Craft’s built-in GraphQL queries don’t define an |
Beta Was this translation helpful? Give feedback.
Sorry, I tested by passing specific IDs into the param, which does in fact result in an inclusive search (
or):{ { entries( relatedToEntries: { id: [129, 122] } ) { # ... } }You could reformat your query like so, which would also result in an inclusive search:
{ entries( relatedToEntries: [ { slug: ["test", "test1"] section: ["page", "news"] } ] ) { # ... } }(Though I realize that isn’t quite the same as what you’re going for – as you don’t want to pull in
test1from thenewssection, ortestfrom thepagesection, etc.)