protected function EntitySchemaProvider::getQueryArguments in GraphQL 8
Same name and namespace in other branches
- 8.2 src/SchemaProvider/EntitySchemaProvider.php \Drupal\graphql\SchemaProvider\EntitySchemaProvider::getQueryArguments()
Utility function to retrieve the list of arguments for an entity query.
Parameters
\Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $definition: The entity type definition.
Return value
array The list of arguments for potential use in the entity query.
1 call to EntitySchemaProvider::getQueryArguments()
- EntitySchemaProvider::getQuerySchema in src/
SchemaProvider/ EntitySchemaProvider.php
File
- src/
SchemaProvider/ EntitySchemaProvider.php, line 121
Class
- EntitySchemaProvider
- Generates a GraphQL Schema for content entity types.
Namespace
Drupal\graphql\SchemaProviderCode
protected function getQueryArguments(EntityDataDefinitionInterface $definition) {
$args = [];
foreach ($definition
->getPropertyDefinitions() as $fieldName => $fieldDefinition) {
if (!$fieldDefinition instanceof FieldDefinitionInterface) {
continue;
}
$storage = $fieldDefinition
->getFieldStorageDefinition();
if (!$storage
->isQueryable()) {
continue;
}
// Fetch the main property's definition and resolve it's type.
$mainPropertyName = $storage
->getMainPropertyName();
$mainProperty = $storage
->getPropertyDefinition($mainPropertyName);
if (!($propertyType = $this->typeResolver
->resolveRecursive($mainProperty))) {
continue;
}
$wrappedType = $propertyType;
// Extract the wrapped type of the main property.
while ($wrappedType instanceof ModifierInterface) {
$wrappedType = $wrappedType
->getWrappedType();
}
// We only support scalars and enums as arguments.
if (!($wrappedType instanceof ScalarType || $wrappedType instanceof EnumType)) {
continue;
}
$args[$fieldName] = [
'type' => new ListModifier($wrappedType),
'description' => $fieldDefinition
->getDescription(),
];
}
return $args;
}