File tree 5 files changed +44
-2
lines changed
5 files changed +44
-2
lines changed Original file line number Diff line number Diff line change
1
+ dataproducer_populate_default_values : true
Original file line number Diff line number Diff line change @@ -66,3 +66,13 @@ graphql.default_persisted_query_configuration:
66
66
67
67
plugin.plugin_configuration.persisted_query.* :
68
68
type : graphql.default_persisted_query_configuration
69
+
70
+ graphql.settings :
71
+ type : config_object
72
+ label : " GraphQL Settings"
73
+ mapping :
74
+ # @todo Remove in GraphQL 5.
75
+ dataproducer_populate_default_values :
76
+ type : boolean
77
+ label : " Populate dataproducer context default values"
78
+ description : " Legacy setting: Populate dataproducer context default values before executing the resolve method. Set this to true to be future-proof. This setting is deprecated and will be removed in a future release."
Original file line number Diff line number Diff line change @@ -69,3 +69,15 @@ function graphql_update_8001(): void {
69
69
*/
70
70
function graphql_update_8400() :void {
71
71
}
72
+
73
+ /**
74
+ * Preserve dataproducer default value behavior for old installations.
75
+ *
76
+ * Set dataproducer_populate_default_values to TRUE after you verified that your
77
+ * dataproducers are still working with the new default value behavior.
78
+ */
79
+ function graphql_update_10400() :void {
80
+ \Drupal::configFactory()->getEditable('graphql.settings')
81
+ ->set('dataproducer_populate_default_values', FALSE)
82
+ ->save();
83
+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,13 @@ class DataProducerPluginManager extends DefaultPluginManager {
35
35
*/
36
36
protected $ resultCacheBackend ;
37
37
38
+ /**
39
+ * Backwards compatibility flag to populate context defaults or not.
40
+ *
41
+ * @todo Remove in 5.x.
42
+ */
43
+ protected bool $ populateContextDefaults = TRUE ;
44
+
38
45
/**
39
46
* DataProducerPluginManager constructor.
40
47
*
@@ -83,6 +90,18 @@ public function __construct(
83
90
$ this ->requestStack = $ requestStack ;
84
91
$ this ->contextsManager = $ contextsManager ;
85
92
$ this ->resultCacheBackend = $ resultCacheBackend ;
93
+
94
+ // We don't use dependency injection here to avoid a constructor signature
95
+ // change.
96
+ $ this ->populateContextDefaults = \Drupal::config ('graphql.settings ' )->get ('dataproducer_populate_default_values ' , TRUE );
97
+ }
98
+
99
+ /**
100
+ * {@inheritdoc}
101
+ */
102
+ public function createInstance ($ plugin_id , array $ configuration = []) {
103
+ $ configuration ['dataproducer_populate_default_values ' ] = $ this ->populateContextDefaults ;
104
+ return parent ::createInstance ($ plugin_id , $ configuration );
86
105
}
87
106
88
107
/**
Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ public function resolveField(FieldContext $field) {
50
50
if (!method_exists ($ this , 'resolve ' )) {
51
51
throw new \LogicException ('Missing data producer resolve method. ' );
52
52
}
53
-
54
- $ context = $ this ->getContextValuesWithDefaults ();
53
+ $ populateDefaulktValues = $ this -> configuration [ ' dataproducer_populate_default_values ' ] ?? TRUE ;
54
+ $ context = $ populateDefaulktValues ? $ this ->getContextValuesWithDefaults () : $ this -> getContextValues ();
55
55
return call_user_func_array (
56
56
[$ this , 'resolve ' ],
57
57
array_values (array_merge ($ context , [$ field ]))
You can’t perform that action at this time.
0 commit comments