private function populateObject(Type $type, $data, $multiple = false, ResolveInfo $info)
    {
        if (!$data) {
            return $data;
        }

        if ($multiple) {
            return \array_map(function ($data) use ($type, $info) {
                return $this->populateObject($type, $data, false, $info);
            }, $data);
        }

        if ($type instanceof EnumType) {
            $instance = $this->getTypeClassInstance($type->name);
            if ($instance) {
                $this->accessor->setValue($instance, 'value', $data);

                return $instance;
            } else {
                return $data;
            }
        } elseif ($type instanceof InputObjectType) {
            $instance = $this->getTypeClassInstance($type->name);
            if (!$instance) {
                return $data;
            }

            $fields = $type->getFields();

            foreach ($fields as $name => $field) {
                $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name));

                if ($field->getType() instanceof ListOfType) {
                    $fieldValue = $this->populateObject($field->getType()->getWrappedType(), $fieldData, true, $info);
                } else {
                    $fieldValue = $this->populateObject($field->getType(), $fieldData, false, $info);
                }

                $this->accessor->setValue($instance, $name, $fieldValue);
            }

            return $instance;
        } else {
            return $data;
        }
    }
private function populateObject(Type $type, $data, $multiple = false, ResolveInfo $info)
    {
        if (!$data) {
            return $data;
        }

        if ($multiple) {
            return \array_map(function ($data) use ($type, $info) {
                return $this->populateObject($type, $data, false, $info);
            }, $data);
        }

        if ($type instanceof EnumType) {
            $instance = $this->getTypeClassInstance($type->name);
            if ($instance) {
                $this->accessor->setValue($instance, 'value', $data);

                return $instance;
            } else {
                return $data;
            }
        } elseif ($type instanceof InputObjectType) {
            $instance = $this->getTypeClassInstance($type->name);
            if (!$instance) {
                return $data;
            }

            $fields = $type->getFields();

            foreach ($fields as $name => $field) {
                $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name));

                if ($field->getType() instanceof ListOfType) {
                    $fieldValue = $this->populateObject($field->getType()->getWrappedType(), $fieldData, true, $info);
                } else {
                    $fieldValue = $this->populateObject($field->getType(), $fieldData, false, $info);
                }

                $this->accessor->setValue($instance, $name, $fieldValue);
            }

            return $instance;
        } else {
            return $data;
        }
    }
private function populateObject ( Type $ type , $ data , $ multiple = false , ResolveInfo $ info ) { if ( ! $ data ) { return $ data ; } if ( $ multiple ) { return \ array_map ( function ( $ data ) use ( $ type , $ info ) { return $ this -> populateObject ( $ type , $ data , false , $ info ) ; } , $ data ) ; } if ( $ type instanceof EnumType ) { $ instance = $ this -> getTypeClassInstance ( $ type -> name ) ; if ( $ instance ) { $ this -> accessor -> setValue ( $ instance , 'value' , $ data ) ; return $ instance ; } else { return $ data ; } } elseif ( $ type instanceof InputObjectType ) { $ instance = $ this -> getTypeClassInstance ( $ type -> name ) ; if ( ! $ instance ) { return $ data ; } $ fields = $ type -> getFields ( ) ; foreach ( $ fields as $ name => $ field ) { $ fieldData = $ this -> accessor -> getValue ( $ data , \ sprintf ( '[%s]' , $ name ) ) ; if ( $ field -> getType ( ) instanceof ListOfType ) { $ fieldValue = $ this -> populateObject ( $ field -> getType ( ) -> getWrappedType ( ) , $ fieldData , true , $ info ) ; } else { $ fieldValue = $ this -> populateObject ( $ field -> getType ( ) , $ fieldData , false , $ info ) ; } $ this -> accessor -> setValue ( $ instance , $ name , $ fieldValue ) ; } return $ instance ; } else { return $ data ; } }
Populate an object based on type with given data.

@param Type        $type
@param mixed       $data
@param bool        $multiple
@param ResolveInfo $info

@return mixed
Populate an object based on type with given data .