Skip to content

Commit

Permalink
Only include entry types that are actually queryable
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 14, 2024
1 parent 86150f4 commit 20b1be7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/gql/arguments/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use craft\elements\Entry as EntryElement;
use craft\gql\base\StructureElementArguments;
use craft\gql\types\QueryArgument;
use craft\helpers\Gql;
use craft\models\EntryType;
use GraphQL\Type\Definition\Type;

Expand Down Expand Up @@ -118,13 +119,27 @@ public static function getContentArguments(): array
{
$gqlService = Craft::$app->getGql();
return $gqlService->getOrSetContentArguments(EntryElement::class, function() use ($gqlService): array {
// include all entry types' field layouts, not just the ones from sections in the schema
// because they could be used by Matrix fields
$fieldLayouts = array_map(
fn(EntryType $entryType) => $entryType->getFieldLayout(),
Craft::$app->getEntries()->getAllEntryTypes(),
);
return $gqlService->defineContentArgumentsForFieldLayouts(EntryElement::class, $fieldLayouts);
/** @var EntryType[] $entryTypes */
$entryTypes = [];

foreach (Gql::getSchemaContainedSections() as $section) {
foreach ($section->getEntryTypes() as $entryType) {
$entryTypes[$entryType->id] = $entryType;
}
}

foreach (Gql::getSchemaContainedNestedEntryFields() as $field) {
foreach ($field->getFieldLayoutProviders() as $entryType) {
/** @var EntryType $entryType */
$entryTypes[$entryType->id] = $entryType;
}
}

$arguments = [];
foreach ($entryTypes as $entryType) {
$arguments += $gqlService->getFieldLayoutArguments($entryType->getFieldLayout());
}
return $arguments;
});
}
}

0 comments on commit 20b1be7

Please sign in to comment.