Skip to content

Commit 6b97f39

Browse files
committed
Fixing views derivers.
1 parent f0f390c commit 6b97f39

7 files changed

Lines changed: 79 additions & 61 deletions

File tree

modules/graphql_core/src/Plugin/Deriver/Fields/ViewDeriver.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3333
$id = implode('-', [$viewId, $displayId, 'view']);
3434
$info = $this->getArgumentsInfo($display->getOption('arguments') ?: []);
3535
$arguments = [];
36-
$arguments += $this->getContextualArguments($info, $id);
36+
$arguments += $this->getContextualArguments($display, $info, $id);
3737
$arguments += $this->getPagerArguments($display);
3838
$arguments += $this->getSortArguments($display, $id);
3939
$arguments += $this->getFilterArguments($display, $id);
4040
$types = $this->getTypes($info);
4141

4242
$this->derivatives[$id] = [
43-
'id' => $id,
44-
'name' => $display->getGraphQLQueryName(),
45-
'type' => $display->getGraphQLResultName(),
46-
'parents' => $types,
47-
'multi' => FALSE,
48-
'arguments' => $arguments,
49-
'view' => $viewId,
50-
'display' => $displayId,
51-
'paged' => $this->isPaged($display),
52-
'arguments_info' => $info,
53-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
43+
'id' => $id,
44+
'name' => $display->getGraphQLQueryName(),
45+
'type' => $display->getGraphQLResultName(),
46+
'parents' => $types,
47+
'multi' => FALSE,
48+
'arguments' => $arguments,
49+
'view' => $viewId,
50+
'display' => $displayId,
51+
'paged' => $this->isPaged($display),
52+
'arguments_info' => $info,
53+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
5454
}
5555
}
5656

@@ -60,19 +60,24 @@ public function getDerivativeDefinitions($basePluginDefinition) {
6060
/**
6161
* Helper function to return the contextual filter argument if any exist.
6262
*
63+
* @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $display
64+
* The display plugin.
6365
* @param array $arguments
6466
* The array of available arguments.
6567
* @param $id
6668
* The plugin derivative id.
6769
*
6870
* @return array
6971
* The contextual filter argument if applicable.
72+
*
73+
* The contextual filter argument if applicable.
7074
*/
71-
protected function getContextualArguments(array $arguments, $id) {
75+
protected function getContextualArguments(DisplayPluginInterface $display, array $arguments, $id) {
76+
/** @var \Drupal\graphql\Plugin\views\display\GraphQL $display */
7277
if (!empty($arguments)) {
7378
return [
7479
'contextualFilter' => [
75-
'type' => StringHelper::camelCase([$id, 'contextual', 'filter', 'input']),
80+
'type' => $display->getGraphQLContextualFilterInputName(),
7681
'multi' => FALSE,
7782
'nullable' => TRUE,
7883
],
@@ -94,6 +99,7 @@ protected function getContextualArguments(array $arguments, $id) {
9499
* The sort arguments if any exposed sorts are available.
95100
*/
96101
protected function getSortArguments(DisplayPluginInterface $display, $id) {
102+
/** @var \Drupal\graphql\Plugin\views\display\GraphQL $display */
97103
$sorts = array_filter($display->getOption('sorts') ?: [], function($sort) {
98104
return $sort['exposed'];
99105
});
@@ -129,13 +135,14 @@ protected function getSortArguments(DisplayPluginInterface $display, $id) {
129135
* The filter argument if any exposed filters are available.
130136
*/
131137
protected function getFilterArguments(DisplayPluginInterface $display, $id) {
138+
/** @var \Drupal\graphql\Plugin\views\display\GraphQL $display */
132139
$filters = array_filter($display->getOption('filters') ?: [], function($filter) {
133140
return array_key_exists('exposed', $filter) && $filter['exposed'];
134141
});
135142

136143
return !empty($filters) ? [
137144
'filter' => [
138-
'type' => StringHelper::camelCase([$id, 'filter', 'input']),
145+
'type' => $display->getGraphQLFilterInputName(),
139146
'multi' => FALSE,
140147
'nullable' => TRUE,
141148
],

modules/graphql_core/src/Plugin/Deriver/Fields/ViewResultCountDeriver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3333

3434
$id = implode('-', [$viewId, $displayId, 'result', 'count']);
3535
$this->derivatives[$id] = [
36-
'id' => $id,
37-
'type' => 'Int',
38-
'parents' => [$display->getGraphQLResultName()],
39-
'view' => $viewId,
40-
'display' => $displayId,
41-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
36+
'id' => $id,
37+
'type' => 'Int',
38+
'parents' => [$display->getGraphQLResultName()],
39+
'view' => $viewId,
40+
'display' => $displayId,
41+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
4242
}
4343
}
4444

modules/graphql_core/src/Plugin/Deriver/Fields/ViewResultListDeriver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3131
$id = implode('-', [$viewId, $displayId, 'result', 'list']);
3232
$style = $this->getViewStyle($view, $displayId);
3333
$this->derivatives[$id] = [
34-
'id' => $id,
35-
'type' => $type,
36-
'parents' => [$display->getGraphQLResultName()],
37-
'multi' => TRUE,
38-
'view' => $viewId,
39-
'display' => $displayId,
40-
'uses_fields' => $style->usesFields(),
41-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
34+
'id' => $id,
35+
'type' => $type,
36+
'parents' => [$display->getGraphQLResultName()],
37+
'multi' => TRUE,
38+
'view' => $viewId,
39+
'display' => $displayId,
40+
'uses_fields' => $style->usesFields(),
41+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
4242
}
4343
}
4444

modules/graphql_core/src/Plugin/Deriver/Fields/ViewRowFieldDeriver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3636
$alias = $rowPlugin->getFieldKeyAlias($name);
3737

3838
$this->derivatives[$id] = [
39-
'id' => $id,
40-
'name' => $alias,
41-
'type' => 'String',
42-
'parents' => [$display->getGraphQLRowName()],
43-
'view' => $viewId,
44-
'display' => $displayId,
45-
'field' => $alias,
46-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
39+
'id' => $id,
40+
'name' => $alias,
41+
'type' => 'String',
42+
'parents' => [$display->getGraphQLRowName()],
43+
'view' => $viewId,
44+
'display' => $displayId,
45+
'field' => $alias,
46+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
4747
}
4848
}
4949
}

modules/graphql_core/src/Plugin/Deriver/InputTypes/ViewContextualFilterInputDeriver.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
2626
continue;
2727
}
2828

29+
/** @var \Drupal\graphql\Plugin\views\display\GraphQL $display */
2930
$display = $this->getViewDisplay($view, $displayId);
3031
$argumentsInfo = $this->getArgumentsInfo($display->getOption('arguments') ?: []);
3132
if (!empty($argumentsInfo)) {
@@ -34,18 +35,18 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3435
]);
3536

3637
$this->derivatives[$id] = [
37-
'id' => $id,
38-
'name' => StringHelper::camelCase([$viewId, $displayId, 'view', 'contextual', 'filter', 'input']),
39-
'fields' => array_fill_keys(array_keys($argumentsInfo), [
40-
'type' => 'String',
41-
// Always expose contextual filters as nullable. Let views module
42-
// decide what to do if value is missing.
43-
'nullable' => TRUE,
44-
'multi' => FALSE,
45-
]),
46-
'view' => $viewId,
47-
'display' => $displayId,
48-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
38+
'id' => $id,
39+
'name' => $display->getGraphQLContextualFilterInputName(),
40+
'fields' => array_fill_keys(array_keys($argumentsInfo), [
41+
'type' => 'String',
42+
// Always expose contextual filters as nullable. Let views module
43+
// decide what to do if value is missing.
44+
'nullable' => TRUE,
45+
'multi' => FALSE,
46+
]),
47+
'view' => $viewId,
48+
'display' => $displayId,
49+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
4950
}
5051
}
5152
}

modules/graphql_core/src/Plugin/Deriver/InputTypes/ViewFilterInputDeriver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3535
return array_key_exists('exposed', $filter) && $filter['exposed'];
3636
}), function($carry, $current) {
3737
return $carry + [
38-
$current['expose']['identifier'] => $current,
39-
];
38+
$current['expose']['identifier'] => $current,
39+
];
4040
}, []);
4141

4242
// If there are no exposed filters, don't create the derivative.
@@ -57,12 +57,12 @@ public function getDerivativeDefinitions($basePluginDefinition) {
5757
}, $filters);
5858

5959
$this->derivatives[$id] = [
60-
'id' => $id,
61-
'name' => $display->getGraphQLFilterInputName(),
62-
'fields' => $fields,
63-
'view' => $viewId,
64-
'display' => $displayId,
65-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
60+
'id' => $id,
61+
'name' => $display->getGraphQLFilterInputName(),
62+
'fields' => $fields,
63+
'view' => $viewId,
64+
'display' => $displayId,
65+
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
6666
}
6767

6868
}

src/Plugin/views/display/GraphQL.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getGraphQLQueryName() {
112112
}
113113

114114
/**
115-
* Gets the result name based on user defined query name or the default one.
115+
* Gets the result name.
116116
*
117117
* @return string
118118
* Result name.
@@ -122,7 +122,7 @@ public function getGraphQLResultName() {
122122
}
123123

124124
/**
125-
* Gets the row name based on user defined query name or the default one.
125+
* Gets the row name.
126126
*
127127
* @return string
128128
* Row name.
@@ -132,7 +132,7 @@ public function getGraphQLRowName() {
132132
}
133133

134134
/**
135-
* Gets the filter input name based on user defined query name or the default one.
135+
* Gets the filter input name..
136136
*
137137
* @return string
138138
* Result name.
@@ -142,7 +142,17 @@ public function getGraphQLFilterInputName() {
142142
}
143143

144144
/**
145-
* Returns the id based on user-provided query name or the default one.
145+
* Gets the contextual filter input name.
146+
*
147+
* @return string
148+
* Result name.
149+
*/
150+
public function getGraphQLContextualFilterInputName() {
151+
return $this->getGraphQLName('contextual_filter_input', TRUE);
152+
}
153+
154+
/**
155+
* Returns the formatted name.
146156
*
147157
* @param string|null $suffix
148158
* Id suffix, eg. row, result.

0 commit comments

Comments
 (0)