protected function createFields(Manager $manager)
    {
        $fieldMap = [];
        $instance = $this->getDataObjectInstance();
        $extraDataObjects = $this->nestedDataObjectClasses();
        $this->fields->removeDuplicates('Name');

        if (!$this->fields->exists()) {
            $this->addFields(
                Config::inst()->get(self::class, 'default_fields')
            );
        }

        $resolver = function ($obj, $args, $context, $info) {
            /**
             * @var DataObject $obj
             */
            $field = $obj->obj($info->fieldName);
            // return the raw field value, or checks like `is_numeric()` fail
            if ($field instanceof DBField && $field->isInternalGraphQLType()) {
                return $field->getValue();
            }
            return $field;
        };

        foreach ($this->fields as $fieldData) {
            $fieldName = $fieldData->Name;
            if (!StaticSchema::inst()->isValidFieldName($instance, $fieldName)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Invalid field "%s" on %s',
                        $fieldName,
                        $this->getDataObjectClass()
                    )
                );
            }

            $result = $instance->obj($fieldName);

            if ($result instanceof SS_List) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Fieldname %s added to %s returns a list. This should be defined as a nested query using addNestedQuery(%s)',
                        $fieldName,
                        $this->getDataObjectClass(),
                        $fieldName
                    )
                );
            }

            if ($result instanceof DBField) {
                /** @var DBField|TypeCreatorExtension $result */
                $fieldMap[$fieldName] = [];
                $fieldMap[$fieldName]['type'] = $result->getGraphQLType($manager);
                $fieldMap[$fieldName]['resolve'] = $resolver;
                $fieldMap[$fieldName]['description'] = $fieldData->Description;
            }
        }

        foreach ($extraDataObjects as $fieldName => $className) {
            $description = $this->getFieldDescription($fieldName);
            $fieldMap[$fieldName] = [
                'type' => StaticSchema::inst()->fetchFromManager($className, $manager),
                'description' => $description,
                'resolve' => $resolver,
            ];
        }

        foreach ($this->nestedQueries as $name => $scaffolder) {
            $scaffold = $scaffolder->scaffold($manager);
            $scaffold['name'] = $name;
            $fieldMap[$name] = $scaffold;
        }

        return $fieldMap;
    }
protected function createFields(Manager $manager)
    {
        $fieldMap = [];
        $instance = $this->getDataObjectInstance();
        $extraDataObjects = $this->nestedDataObjectClasses();
        $this->fields->removeDuplicates('Name');

        if (!$this->fields->exists()) {
            $this->addFields(
                Config::inst()->get(self::class, 'default_fields')
            );
        }

        $resolver = function ($obj, $args, $context, $info) {
            /**
             * @var DataObject $obj
             */
            $field = $obj->obj($info->fieldName);
            // return the raw field value, or checks like `is_numeric()` fail
            if ($field instanceof DBField && $field->isInternalGraphQLType()) {
                return $field->getValue();
            }
            return $field;
        };

        foreach ($this->fields as $fieldData) {
            $fieldName = $fieldData->Name;
            if (!StaticSchema::inst()->isValidFieldName($instance, $fieldName)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Invalid field "%s" on %s',
                        $fieldName,
                        $this->getDataObjectClass()
                    )
                );
            }

            $result = $instance->obj($fieldName);

            if ($result instanceof SS_List) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Fieldname %s added to %s returns a list. This should be defined as a nested query using addNestedQuery(%s)',
                        $fieldName,
                        $this->getDataObjectClass(),
                        $fieldName
                    )
                );
            }

            if ($result instanceof DBField) {
                /** @var DBField|TypeCreatorExtension $result */
                $fieldMap[$fieldName] = [];
                $fieldMap[$fieldName]['type'] = $result->getGraphQLType($manager);
                $fieldMap[$fieldName]['resolve'] = $resolver;
                $fieldMap[$fieldName]['description'] = $fieldData->Description;
            }
        }

        foreach ($extraDataObjects as $fieldName => $className) {
            $description = $this->getFieldDescription($fieldName);
            $fieldMap[$fieldName] = [
                'type' => StaticSchema::inst()->fetchFromManager($className, $manager),
                'description' => $description,
                'resolve' => $resolver,
            ];
        }

        foreach ($this->nestedQueries as $name => $scaffolder) {
            $scaffold = $scaffolder->scaffold($manager);
            $scaffold['name'] = $name;
            $fieldMap[$name] = $scaffold;
        }

        return $fieldMap;
    }
protected function createFields ( Manager $ manager ) { $ fieldMap = [ ] ; $ instance = $ this -> getDataObjectInstance ( ) ; $ extraDataObjects = $ this -> nestedDataObjectClasses ( ) ; $ this -> fields -> removeDuplicates ( 'Name' ) ; if ( ! $ this -> fields -> exists ( ) ) { $ this -> addFields ( Config :: inst ( ) -> get ( self :: class , 'default_fields' ) ) ; } $ resolver = function ( $ obj , $ args , $ context , $ info ) { /**
             * @var DataObject $obj
             */ $ field = $ obj -> obj ( $ info -> fieldName ) ; // return the raw field value, or checks like `is_numeric()` fail if ( $ field instanceof DBField && $ field -> isInternalGraphQLType ( ) ) { return $ field -> getValue ( ) ; } return $ field ; } ; foreach ( $ this -> fields as $ fieldData ) { $ fieldName = $ fieldData -> Name ; if ( ! StaticSchema :: inst ( ) -> isValidFieldName ( $ instance , $ fieldName ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid field "%s" on %s' , $ fieldName , $ this -> getDataObjectClass ( ) ) ) ; } $ result = $ instance -> obj ( $ fieldName ) ; if ( $ result instanceof SS_List ) { throw new InvalidArgumentException ( sprintf ( 'Fieldname %s added to %s returns a list. This should be defined as a nested query using addNestedQuery(%s)' , $ fieldName , $ this -> getDataObjectClass ( ) , $ fieldName ) ) ; } if ( $ result instanceof DBField ) { /** @var DBField|TypeCreatorExtension $result */ $ fieldMap [ $ fieldName ] = [ ] ; $ fieldMap [ $ fieldName ] [ 'type' ] = $ result -> getGraphQLType ( $ manager ) ; $ fieldMap [ $ fieldName ] [ 'resolve' ] = $ resolver ; $ fieldMap [ $ fieldName ] [ 'description' ] = $ fieldData -> Description ; } } foreach ( $ extraDataObjects as $ fieldName => $ className ) { $ description = $ this -> getFieldDescription ( $ fieldName ) ; $ fieldMap [ $ fieldName ] = [ 'type' => StaticSchema :: inst ( ) -> fetchFromManager ( $ className , $ manager ) , 'description' => $ description , 'resolve' => $ resolver , ] ; } foreach ( $ this -> nestedQueries as $ name => $ scaffolder ) { $ scaffold = $ scaffolder -> scaffold ( $ manager ) ; $ scaffold [ 'name' ] = $ name ; $ fieldMap [ $ name ] = $ scaffold ; } return $ fieldMap ; }
Validates the raw field map and creates a map suitable for ObjectType

@param  Manager $manager
@return array
Validates the raw field map and creates a map suitable for ObjectType