public function create(string $className, string $typeName): Type
    {
        $type = new InputObjectType([
            'name' => $typeName,
            'description' => 'Type to specify conditions on fields',
            'fields' => function () use ($className, $typeName): array {
                $filters = [];
                $metadata = $this->entityManager->getClassMetadata($className);

                // Get custom operators
                $this->readCustomOperatorsFromAnnotation($metadata->reflClass);

                // Get all scalar fields
                foreach ($metadata->fieldMappings as $mapping) {
                    if ($mapping['id'] ?? false) {
                        $leafType = Type::id();
                    } else {
                        /** @var LeafType $leafType */
                        $leafType = $this->types->get($mapping['type']);
                    }

                    $fieldName = $mapping['fieldName'];
                    $operators = $this->getOperators($fieldName, $leafType, false, false);

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                // Get all collection fields
                foreach ($metadata->associationMappings as $mapping) {
                    $fieldName = $mapping['fieldName'];
                    $operators = $this->getOperators($fieldName, Type::id(), true, $metadata->isCollectionValuedAssociation($fieldName));

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                // Get all custom fields defined by custom operators
                foreach ($this->customOperators as $fieldName => $customOperators) {
                    $operators = [];
                    /** @var Filter $customOperator */
                    foreach ($customOperators as $customOperator) {
                        /** @var LeafType $leafType */
                        $leafType = $this->types->get($customOperator->type);
                        $operators[$customOperator->operator] = $leafType;
                    }

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                return $filters;
            },
        ]);

        return $type;
    }
public function create(string $className, string $typeName): Type
    {
        $type = new InputObjectType([
            'name' => $typeName,
            'description' => 'Type to specify conditions on fields',
            'fields' => function () use ($className, $typeName): array {
                $filters = [];
                $metadata = $this->entityManager->getClassMetadata($className);

                // Get custom operators
                $this->readCustomOperatorsFromAnnotation($metadata->reflClass);

                // Get all scalar fields
                foreach ($metadata->fieldMappings as $mapping) {
                    if ($mapping['id'] ?? false) {
                        $leafType = Type::id();
                    } else {
                        /** @var LeafType $leafType */
                        $leafType = $this->types->get($mapping['type']);
                    }

                    $fieldName = $mapping['fieldName'];
                    $operators = $this->getOperators($fieldName, $leafType, false, false);

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                // Get all collection fields
                foreach ($metadata->associationMappings as $mapping) {
                    $fieldName = $mapping['fieldName'];
                    $operators = $this->getOperators($fieldName, Type::id(), true, $metadata->isCollectionValuedAssociation($fieldName));

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                // Get all custom fields defined by custom operators
                foreach ($this->customOperators as $fieldName => $customOperators) {
                    $operators = [];
                    /** @var Filter $customOperator */
                    foreach ($customOperators as $customOperator) {
                        /** @var LeafType $leafType */
                        $leafType = $this->types->get($customOperator->type);
                        $operators[$customOperator->operator] = $leafType;
                    }

                    $filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
                }

                return $filters;
            },
        ]);

        return $type;
    }
public function create ( string $ className , string $ typeName ) : Type { $ type = new InputObjectType ( [ 'name' => $ typeName , 'description' => 'Type to specify conditions on fields' , 'fields' => function ( ) use ( $ className , $ typeName ) : array { $ filters = [ ] ; $ metadata = $ this -> entityManager -> getClassMetadata ( $ className ) ; // Get custom operators $ this -> readCustomOperatorsFromAnnotation ( $ metadata -> reflClass ) ; // Get all scalar fields foreach ( $ metadata -> fieldMappings as $ mapping ) { if ( $ mapping [ 'id' ] ?? false ) { $ leafType = Type :: id ( ) ; } else { /** @var LeafType $leafType */ $ leafType = $ this -> types -> get ( $ mapping [ 'type' ] ) ; } $ fieldName = $ mapping [ 'fieldName' ] ; $ operators = $ this -> getOperators ( $ fieldName , $ leafType , false , false ) ; $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } // Get all collection fields foreach ( $ metadata -> associationMappings as $ mapping ) { $ fieldName = $ mapping [ 'fieldName' ] ; $ operators = $ this -> getOperators ( $ fieldName , Type :: id ( ) , true , $ metadata -> isCollectionValuedAssociation ( $ fieldName ) ) ; $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } // Get all custom fields defined by custom operators foreach ( $ this -> customOperators as $ fieldName => $ customOperators ) { $ operators = [ ] ; /** @var Filter $customOperator */ foreach ( $ customOperators as $ customOperator ) { /** @var LeafType $leafType */ $ leafType = $ this -> types -> get ( $ customOperator -> type ) ; $ operators [ $ customOperator -> operator ] = $ leafType ; } $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } return $ filters ; } , ] ) ; return $ type ; }
Create an InputObjectType from a Doctrine entity to
specify condition on fields.

@param string $className class name of Doctrine entity
@param string $typeName GraphQL type name

@return InputObjectType
Create an InputObjectType from a Doctrine entity to specify condition on fields .