@@ -268,6 +268,44 @@ def to_param
268
268
end
269
269
end
270
270
271
+ describe "passing a document into #execute" do
272
+ it "sends the updated data" do
273
+ query_str = <<-GRAPHQL
274
+ subscription ($id: ID!){
275
+ payload(id: $id) { str, int }
276
+ }
277
+ GRAPHQL
278
+
279
+ document = GraphQL . parse ( query_str )
280
+
281
+ # Initial subscriptions
282
+ response = schema . execute ( nil , document : document , context : { socket : "1" } , variables : { "id" => "100" } , root_value : root_object )
283
+
284
+ # This difference is because of how `SKIP` is handled.
285
+ # Honestly the new way is probably better, since it puts a value there.
286
+ empty_response = if TESTING_INTERPRETER && schema == ClassBasedInMemoryBackend ::Schema
287
+ { }
288
+ else
289
+ nil
290
+ end
291
+
292
+ # Initial response is nil, no broadcasts yet
293
+ assert_equal ( empty_response , response [ "data" ] )
294
+ assert_equal [ ] , deliveries [ "1" ]
295
+
296
+ # Application stuff happens.
297
+ # The application signals graphql via `subscriptions.trigger`:
298
+ schema . subscriptions . trigger ( :payload , { "id" => "100" } , root_object . payload )
299
+ # Symobls are OK too
300
+ schema . subscriptions . trigger ( :payload , { :id => "100" } , root_object . payload )
301
+ schema . subscriptions . trigger ( "payload" , { "id" => "300" } , nil )
302
+
303
+ # Let's see what GraphQL sent over the wire:
304
+ assert_equal ( { "str" => "Update" , "int" => 1 } , deliveries [ "1" ] [ 0 ] [ "data" ] [ "payload" ] )
305
+ assert_equal ( { "str" => "Update" , "int" => 2 } , deliveries [ "1" ] [ 1 ] [ "data" ] [ "payload" ] )
306
+ end
307
+ end
308
+
271
309
describe "subscribing" do
272
310
it "doesn't call the subscriptions for invalid queries" do
273
311
query_str = <<-GRAPHQL
0 commit comments