private function collapseType(array $originDefinition): ?array
    {
        $definition = [];
        if ($type = $originDefinition['type'] ?? null) {
            $typeName = $type['name'];
            if (!empty($type['ofType'] ?? [])) {
                $typeName = $type['ofType']['name'];
                $ofType = $type;
                if (in_array($ofType['kind'], ['NON_NULL', 'LIST'])) {
                    $typeName = '%s';
                    while ($ofType) {
                        if ($ofType['kind'] === 'NON_NULL') {
                            $typeName = str_replace('%s', '%s!', $typeName);
                        } elseif ($ofType['kind'] === 'LIST') {
                            $typeName = str_replace('%s', '[%s]', $typeName);
                        } else {
                            $typeName = sprintf($typeName, $ofType['name']);
                            break;
                        }
                        $ofType = $ofType['ofType'] ?? null;
                    }
                }
            }

            $definition['type'] = $typeName;
        }

        if ($fields = $originDefinition['fields'] ?? null) {
            foreach ($fields as $field) {
                $definition['fields'][$field['name']] = $this->collapseType($field);
            }
        }

        if ($inputFields = $originDefinition['inputFields'] ?? null) {
            foreach ($inputFields as $inputField) {
                $definition['inputFields'][$inputField['name']] = $this->collapseType($inputField);
            }
        }

        if ($args = $originDefinition['args'] ?? null) {
            foreach ($args as $arg) {
                $definition['args'][$arg['name']] = $this->collapseType($arg);
            }
        }

        if ($possibleTypes = $originDefinition['possibleTypes'] ?? null) {
            foreach ($possibleTypes as $possibleType) {
                $definition['possibleTypes'][$possibleType['name']] = $this->collapseType($possibleType);
            }
        }

        if ($interfaces = $originDefinition['interfaces'] ?? null) {
            foreach ($interfaces as $interface) {
                $definition['interfaces'][] = $interface['name'];
            }
        }

        if ($enumValues = $originDefinition['enumValues'] ?? null) {
            foreach ($enumValues as $enumValue) {
                $definition['enumValues'][] = $enumValue['name'];
            }
        }

        return empty($definition) ? null : $definition;
    }
private function collapseType(array $originDefinition): ?array
    {
        $definition = [];
        if ($type = $originDefinition['type'] ?? null) {
            $typeName = $type['name'];
            if (!empty($type['ofType'] ?? [])) {
                $typeName = $type['ofType']['name'];
                $ofType = $type;
                if (in_array($ofType['kind'], ['NON_NULL', 'LIST'])) {
                    $typeName = '%s';
                    while ($ofType) {
                        if ($ofType['kind'] === 'NON_NULL') {
                            $typeName = str_replace('%s', '%s!', $typeName);
                        } elseif ($ofType['kind'] === 'LIST') {
                            $typeName = str_replace('%s', '[%s]', $typeName);
                        } else {
                            $typeName = sprintf($typeName, $ofType['name']);
                            break;
                        }
                        $ofType = $ofType['ofType'] ?? null;
                    }
                }
            }

            $definition['type'] = $typeName;
        }

        if ($fields = $originDefinition['fields'] ?? null) {
            foreach ($fields as $field) {
                $definition['fields'][$field['name']] = $this->collapseType($field);
            }
        }

        if ($inputFields = $originDefinition['inputFields'] ?? null) {
            foreach ($inputFields as $inputField) {
                $definition['inputFields'][$inputField['name']] = $this->collapseType($inputField);
            }
        }

        if ($args = $originDefinition['args'] ?? null) {
            foreach ($args as $arg) {
                $definition['args'][$arg['name']] = $this->collapseType($arg);
            }
        }

        if ($possibleTypes = $originDefinition['possibleTypes'] ?? null) {
            foreach ($possibleTypes as $possibleType) {
                $definition['possibleTypes'][$possibleType['name']] = $this->collapseType($possibleType);
            }
        }

        if ($interfaces = $originDefinition['interfaces'] ?? null) {
            foreach ($interfaces as $interface) {
                $definition['interfaces'][] = $interface['name'];
            }
        }

        if ($enumValues = $originDefinition['enumValues'] ?? null) {
            foreach ($enumValues as $enumValue) {
                $definition['enumValues'][] = $enumValue['name'];
            }
        }

        return empty($definition) ? null : $definition;
    }
private function collapseType ( array $ originDefinition ) : ? array { $ definition = [ ] ; if ( $ type = $ originDefinition [ 'type' ] ?? null ) { $ typeName = $ type [ 'name' ] ; if ( ! empty ( $ type [ 'ofType' ] ?? [ ] ) ) { $ typeName = $ type [ 'ofType' ] [ 'name' ] ; $ ofType = $ type ; if ( in_array ( $ ofType [ 'kind' ] , [ 'NON_NULL' , 'LIST' ] ) ) { $ typeName = '%s' ; while ( $ ofType ) { if ( $ ofType [ 'kind' ] === 'NON_NULL' ) { $ typeName = str_replace ( '%s' , '%s!' , $ typeName ) ; } elseif ( $ ofType [ 'kind' ] === 'LIST' ) { $ typeName = str_replace ( '%s' , '[%s]' , $ typeName ) ; } else { $ typeName = sprintf ( $ typeName , $ ofType [ 'name' ] ) ; break ; } $ ofType = $ ofType [ 'ofType' ] ?? null ; } } } $ definition [ 'type' ] = $ typeName ; } if ( $ fields = $ originDefinition [ 'fields' ] ?? null ) { foreach ( $ fields as $ field ) { $ definition [ 'fields' ] [ $ field [ 'name' ] ] = $ this -> collapseType ( $ field ) ; } } if ( $ inputFields = $ originDefinition [ 'inputFields' ] ?? null ) { foreach ( $ inputFields as $ inputField ) { $ definition [ 'inputFields' ] [ $ inputField [ 'name' ] ] = $ this -> collapseType ( $ inputField ) ; } } if ( $ args = $ originDefinition [ 'args' ] ?? null ) { foreach ( $ args as $ arg ) { $ definition [ 'args' ] [ $ arg [ 'name' ] ] = $ this -> collapseType ( $ arg ) ; } } if ( $ possibleTypes = $ originDefinition [ 'possibleTypes' ] ?? null ) { foreach ( $ possibleTypes as $ possibleType ) { $ definition [ 'possibleTypes' ] [ $ possibleType [ 'name' ] ] = $ this -> collapseType ( $ possibleType ) ; } } if ( $ interfaces = $ originDefinition [ 'interfaces' ] ?? null ) { foreach ( $ interfaces as $ interface ) { $ definition [ 'interfaces' ] [ ] = $ interface [ 'name' ] ; } } if ( $ enumValues = $ originDefinition [ 'enumValues' ] ?? null ) { foreach ( $ enumValues as $ enumValue ) { $ definition [ 'enumValues' ] [ ] = $ enumValue [ 'name' ] ; } } return empty ( $ definition ) ? null : $ definition ; }
Collapse type definition

@param array $originDefinition

@return array|null
Collapse type definition