@@ -390,3 +390,197 @@ fn graphql_cannot_remove_subgraph_with_invalid_name() {
390390 assert_ne ! ( resp, success_resp) ;
391391 } ) ;
392392}
393+
394+ #[ test]
395+ fn graphql_can_unassign_deployments ( ) {
396+ run_test ( || async {
397+ let deployment_hash = DeploymentHash :: new ( "subgraph_1" ) . unwrap ( ) ;
398+ create_test_subgraph ( & deployment_hash, TEST_SUBGRAPH_SCHEMA ) . await ;
399+
400+ let unassign_req = send_graphql_request (
401+ json ! ( {
402+ "query" : r#"mutation {
403+ deployment {
404+ unassign(deployment: { hash: "subgraph_1" }){
405+ success
406+ }
407+ }
408+ }"#
409+ } ) ,
410+ VALID_TOKEN ,
411+ )
412+ . await ;
413+
414+ let expected_resp = json ! ( {
415+ "data" : {
416+ "deployment" : {
417+ "unassign" : {
418+ "success" : true ,
419+ }
420+ }
421+ }
422+ } ) ;
423+
424+ let subgraph_node_id = send_graphql_request (
425+ json ! ( {
426+ "query" : r#"query Deployment {
427+ deployment {
428+ info(deployment: { hash: "subgraph_1" }) {
429+ nodeId
430+ }
431+ }
432+ }"#
433+ } ) ,
434+ VALID_TOKEN ,
435+ )
436+ . await ;
437+
438+ let is_node_null = subgraph_node_id[ "data" ] [ "deployment" ] [ "info" ] [ 0 ] [ "nodeId" ] . is_null ( ) ;
439+
440+ assert_eq ! ( unassign_req, expected_resp) ;
441+ assert_eq ! ( is_node_null, true ) ;
442+ } ) ;
443+ }
444+
445+ #[ test]
446+ fn graphql_cannot_unassign_deployments_twice ( ) {
447+ run_test ( || async {
448+ let deployment_hash = DeploymentHash :: new ( "subgraph_1" ) . unwrap ( ) ;
449+ create_test_subgraph ( & deployment_hash, TEST_SUBGRAPH_SCHEMA ) . await ;
450+
451+ send_graphql_request (
452+ json ! ( {
453+ "query" : r#"mutation {
454+ deployment {
455+ unassign(deployment: { hash: "subgraph_1" }){
456+ success
457+ }
458+ }
459+ }"#
460+ } ) ,
461+ VALID_TOKEN ,
462+ )
463+ . await ;
464+
465+ let unassign_again = send_graphql_request (
466+ json ! ( {
467+ "query" : r#"mutation {
468+ deployment {
469+ unassign(deployment: { hash: "subgraph_1" }){
470+ success
471+ }
472+ }
473+ }"#
474+ } ) ,
475+ VALID_TOKEN ,
476+ )
477+ . await ;
478+
479+ let expected_resp = json ! ( {
480+ "data" : {
481+ "deployment" : {
482+ "unassign" : {
483+ "success" : true ,
484+ }
485+ }
486+ }
487+ } ) ;
488+
489+ assert_ne ! ( unassign_again, expected_resp) ;
490+ } ) ;
491+ }
492+
493+ #[ test]
494+ fn graphql_can_reassign_deployment ( ) {
495+ run_test ( || async {
496+ let deployment_hash = DeploymentHash :: new ( "subgraph_1" ) . unwrap ( ) ;
497+ create_test_subgraph ( & deployment_hash, TEST_SUBGRAPH_SCHEMA ) . await ;
498+
499+ let deployment_hash = DeploymentHash :: new ( "subgraph_2" ) . unwrap ( ) ;
500+ create_test_subgraph ( & deployment_hash, TEST_SUBGRAPH_SCHEMA ) . await ;
501+
502+ send_graphql_request (
503+ json ! ( {
504+ "query" : r#"mutation {
505+ deployment {
506+ unassign(deployment: { hash: "subgraph_1" }){
507+ success
508+ }
509+ }
510+ }"#
511+ } ) ,
512+ VALID_TOKEN ,
513+ )
514+ . await ;
515+
516+ let reassign = send_graphql_request (
517+ json ! ( {
518+ "query" : r#"mutation {
519+ deployment {
520+ reassign(deployment: { hash: "subgraph_1" }, node: "test") {
521+ ... on EmptyResponse {
522+ success
523+ }
524+ ... on CompletedWithWarnings {
525+ warnings
526+ }
527+ }
528+ }
529+ }"#
530+ } ) ,
531+ VALID_TOKEN ,
532+ )
533+ . await ;
534+
535+ let expected_resp = json ! ( {
536+ "data" : {
537+ "deployment" : {
538+ "reassign" : {
539+ "success" : true ,
540+ }
541+ }
542+ }
543+ } ) ;
544+
545+ assert_eq ! ( reassign, expected_resp) ;
546+ } ) ;
547+ }
548+
549+ #[ test]
550+ fn graphql_warns_reassign_on_wrong_node_id ( ) {
551+ run_test ( || async {
552+ let deployment_hash = DeploymentHash :: new ( "subgraph_1" ) . unwrap ( ) ;
553+ create_test_subgraph ( & deployment_hash, TEST_SUBGRAPH_SCHEMA ) . await ;
554+
555+ let reassign = send_graphql_request (
556+ json ! ( {
557+ "query" : r#"mutation {
558+ deployment {
559+ reassign(deployment: { hash: "subgraph_1" }, node: "invalid_node") {
560+ ... on EmptyResponse {
561+ success
562+ }
563+ ... on CompletedWithWarnings {
564+ warnings
565+ }
566+ }
567+ }
568+ }"#
569+ } ) ,
570+ VALID_TOKEN ,
571+ )
572+ . await ;
573+
574+ let expected_resp = json ! ( {
575+ "data" : {
576+ "deployment" : {
577+ "reassign" : {
578+ "warnings" : [ "warning: this is the only deployment assigned to 'invalid_node'. Are you sure it is spelled correctly?" ] ,
579+ }
580+ }
581+ }
582+ } ) ;
583+
584+ assert_eq ! ( reassign, expected_resp) ;
585+ } ) ;
586+ }
0 commit comments