src/Generators/SchemaGenerator.php
private function getDefinedTypesFromSchema(Schema $schema, array $definitionFileDirectories): array
    {
        $definedTypes = $this->definitionsParser->getGraphqlDefinitionFilePaths(
            $definitionFileDirectories['types']
        );

        foreach ($definedTypes as $key => $type) {
            $definedTypes[$key] = str_replace('.graphql', '', basename($type));
        }

        $internalTypes = [];
        /**
         * @var string $typeName
         * @var ObjectType $type
         */
        foreach ($schema->getTypeMap() as $typeName => $type) {
            if (! in_array($typeName, $definedTypes) || ! method_exists($type, 'getFields')) {
                continue;
            }

            /**
             * @var string $fieldName
             * @var FieldDefinition $fieldType
             */
            foreach ($type->getFields() as $fieldName => $fieldType) {
                $graphQLType = $fieldType->getType();

                //Every required field is defined by a parent 'NonNullType'
                if (method_exists($graphQLType, 'getWrappedType')) {
                    // Clone the field to prevent pass by reference,
                    // because we want to add a config value unique to this field.
                    $graphQLType = clone $graphQLType->getWrappedType();

                    //We want to know later on wether or not a field is required
                    $graphQLType->config['generator-required'] = true;
                }

                if (! in_array(get_class($graphQLType), $this->supportedGraphQLTypes)) {
                    continue;
                };

                // This retrieves the GraphQL type for this field from the webonyx/graphql-php package
                $internalTypes[$typeName][$fieldName] = $graphQLType;
            }
        }

        return $internalTypes;
    }
private function getDefinedTypesFromSchema(Schema $schema, array $definitionFileDirectories): array
    {
        $definedTypes = $this->definitionsParser->getGraphqlDefinitionFilePaths(
            $definitionFileDirectories['types']
        );

        foreach ($definedTypes as $key => $type) {
            $definedTypes[$key] = str_replace('.graphql', '', basename($type));
        }

        $internalTypes = [];
        /**
         * @var string $typeName
         * @var ObjectType $type
         */
        foreach ($schema->getTypeMap() as $typeName => $type) {
            if (! in_array($typeName, $definedTypes) || ! method_exists($type, 'getFields')) {
                continue;
            }

            /**
             * @var string $fieldName
             * @var FieldDefinition $fieldType
             */
            foreach ($type->getFields() as $fieldName => $fieldType) {
                $graphQLType = $fieldType->getType();

                //Every required field is defined by a parent 'NonNullType'
                if (method_exists($graphQLType, 'getWrappedType')) {
                    // Clone the field to prevent pass by reference,
                    // because we want to add a config value unique to this field.
                    $graphQLType = clone $graphQLType->getWrappedType();

                    //We want to know later on wether or not a field is required
                    $graphQLType->config['generator-required'] = true;
                }

                if (! in_array(get_class($graphQLType), $this->supportedGraphQLTypes)) {
                    continue;
                };

                // This retrieves the GraphQL type for this field from the webonyx/graphql-php package
                $internalTypes[$typeName][$fieldName] = $graphQLType;
            }
        }

        return $internalTypes;
    }
private function getDefinedTypesFromSchema ( Schema $ schema , array $ definitionFileDirectories ) : array { $ definedTypes = $ this -> definitionsParser -> getGraphqlDefinitionFilePaths ( $ definitionFileDirectories [ 'types' ] ) ; foreach ( $ definedTypes as $ key => $ type ) { $ definedTypes [ $ key ] = str_replace ( '.graphql' , '' , basename ( $ type ) ) ; } $ internalTypes = [ ] ; /**
         * @var string $typeName
         * @var ObjectType $type
         */ foreach ( $ schema -> getTypeMap ( ) as $ typeName => $ type ) { if ( ! in_array ( $ typeName , $ definedTypes ) || ! method_exists ( $ type , 'getFields' ) ) { continue ; } /**
             * @var string $fieldName
             * @var FieldDefinition $fieldType
             */ foreach ( $ type -> getFields ( ) as $ fieldName => $ fieldType ) { $ graphQLType = $ fieldType -> getType ( ) ; //Every required field is defined by a parent 'NonNullType' if ( method_exists ( $ graphQLType , 'getWrappedType' ) ) { // Clone the field to prevent pass by reference, // because we want to add a config value unique to this field. $ graphQLType = clone $ graphQLType -> getWrappedType ( ) ; //We want to know later on wether or not a field is required $ graphQLType -> config [ 'generator-required' ] = true ; } if ( ! in_array ( get_class ( $ graphQLType ) , $ this -> supportedGraphQLTypes ) ) { continue ; } ; // This retrieves the GraphQL type for this field from the webonyx/graphql-php package $ internalTypes [ $ typeName ] [ $ fieldName ] = $ graphQLType ; } } return $ internalTypes ; }
Parse defined types from a schema into an array with the native GraphQL Scalar types for each field

@param Schema $schema
@param array $definitionFileDirectories
@return Type[]
Parse defined types from a schema into an array with the native GraphQL Scalar types for each field