Skip to content

Commit

Permalink
ENGCOM-2317: Alphabetize Schema Fields#11 #104
Browse files Browse the repository at this point in the history
 - Merge Pull Request magento/graphql-ce#104 from magento/graphql-ce:11-Alphabetize-Schema-Fields
 - Merged commits:
   1. fa2c3b5
   2. a95879b
   3. 4a28372
   4. b8d2663
   5. f06056a
   6. 1378ed3
  • Loading branch information
magento-engcom-team committed Nov 13, 2018
2 parents 5f976fa + 1378ed3 commit 5c68913
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Expand Up @@ -191,6 +191,16 @@ enumValues(includeDeprecated: true) {
$mergedSchemaResponseFields = array_merge($schemaResponseFieldsFirstHalf, $schemaResponseFieldsSecondHalf);

foreach ($expectedOutput as $searchTerm) {
$sortFields = ['inputFields', 'fields'];
foreach ($sortFields as $sortField) {
isset($searchTerm[$sortField]) && is_array($searchTerm[$sortField])
? usort($searchTerm[$sortField], function ($a, $b) {
$cmpField = 'name';
return isset($a[$cmpField]) && isset($b[$cmpField])
? strcmp($a[$cmpField], $b[$cmpField]) : 0;
}) : null;
}

$this->assertTrue(
(in_array($searchTerm, $mergedSchemaResponseFields)),
'Missing type in the response'
Expand Down
12 changes: 8 additions & 4 deletions lib/internal/Magento/Framework/GraphQl/Config.php
Expand Up @@ -65,12 +65,16 @@ public function getConfigElement(string $configElementName) : ConfigElementInter
}

$fieldsInQuery = $this->queryFields->getFieldsUsedInQuery();
if (isset($data['fields']) && !empty($fieldsInQuery)) {
foreach ($data['fields'] as $fieldName => $fieldConfig) {
if (!isset($fieldsInQuery[$fieldName])) {
unset($data['fields'][$fieldName]);
if (isset($data['fields'])) {
if (!empty($fieldsInQuery)) {
foreach ($data['fields'] as $fieldName => $fieldConfig) {
if (!isset($fieldsInQuery[$fieldName])) {
unset($data['fields'][$fieldName]);
}
}
}

ksort($data['fields']);
}

return $this->configElementFactory->createFromConfigData($data);
Expand Down

0 comments on commit 5c68913

Please sign in to comment.