Skip to content

Commit

Permalink
GraphQl-93: Implement support for variables in query
Browse files Browse the repository at this point in the history
-- Fixes after CR
  • Loading branch information
naydav committed Jan 18, 2019
1 parent 6f585f4 commit 0985244
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/internal/Magento/Framework/GraphQl/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function getConfigElement(string $configElementName) : ConfigElementInter
/**
* Return all type names declared in a GraphQL schema's configuration and their type.
*
* Format is ['name' => 'example value', 'type' = 'example value']
*
* @return array $types
* name string
* type string
*/
public function getDeclaredTypeNames() : array
public function getDeclaredTypes() : array
{
$types = [];
foreach ($this->configData->get(null) as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function createFromConfigData(array $data): ConfigElementInterface
}

/**
* Create type object based off array of configured GraphQL InputType data.
* Create input type object based off array of configured GraphQL InputType data.
*
* Type data must contain name and the type's fields. Optional data includes description.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/Magento/Framework/GraphQl/Query/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setQuery($query, array $variables = null)
]
);
if (isset($variables)) {
$queryFields = array_merge($queryFields, $this->getVariables($variables));
$queryFields = array_merge($queryFields, $this->extracttVariables($variables));
}
} catch (\Exception $e) {
// If a syntax error is encountered do not collect fields
Expand Down Expand Up @@ -75,12 +75,12 @@ public function getFieldsUsedInQuery()
*
* @return string[]
*/
private function getVariables(array $variables): array
private function extracttVariables(array $variables): array
{
$fields = [];
foreach ($variables as $key => $value){
if (is_array($value)){
$fields = array_merge($fields, $this->getVariables($value));
$fields = array_merge($fields, $this->extracttVariables($value));
}
$fields[$key] = $key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function get(string $typeName): TypeInterface
$configElementClass = get_class($configElement);
if (!isset($this->configToTypeMap[$configElementClass])) {
throw new GraphQlInputException(
new Phrase("Type for '{$configElementClass}' has not declared.")
new Phrase(
"No mapping to Webonyx type is declared for '%1' config element type.",
[$configElementClass]
)
);
}

Expand Down

0 comments on commit 0985244

Please sign in to comment.