@@ -843,6 +843,57 @@ func TestThrowsIfUnknownOperationNameIsProvided(t *testing.T) {
843
843
t .Fatalf ("unexpected result, Diff: %v" , testutil .Diff (expectedErrors , result .Errors ))
844
844
}
845
845
}
846
+
847
+ func TestThrowsIfOperationTypeIsUnsupported (t * testing.T ) {
848
+ query := `mutation Mut { a } subscription Sub { a }`
849
+ operations := []string {"Mut" , "Sub" }
850
+
851
+ expectedErrors := [][]gqlerrors.FormattedError {
852
+ {{
853
+ Message : `Schema is not configured for mutations` ,
854
+ Locations : []location.SourceLocation {{Line : 1 , Column : 1 }},
855
+ }},
856
+ {{
857
+ Message : `Schema is not configured for subscriptions` ,
858
+ Locations : []location.SourceLocation {{Line : 1 , Column : 20 }},
859
+ }},
860
+ }
861
+
862
+ schema , err := graphql .NewSchema (graphql.SchemaConfig {
863
+ Query : graphql .NewObject (graphql.ObjectConfig {
864
+ Name : "Query" ,
865
+ Fields : graphql.Fields {
866
+ "a" : & graphql.Field {
867
+ Type : graphql .String ,
868
+ },
869
+ },
870
+ }),
871
+ })
872
+ if err != nil {
873
+ t .Fatalf ("Error in schema %v" , err .Error ())
874
+ }
875
+
876
+ // parse query
877
+ ast := testutil .TestParse (t , query )
878
+
879
+ for opIndex , operation := range operations {
880
+ expectedErrors := expectedErrors [opIndex ]
881
+
882
+ // execute
883
+ ep := graphql.ExecuteParams {
884
+ Schema : schema ,
885
+ AST : ast ,
886
+ OperationName : operation ,
887
+ }
888
+ result := testutil .TestExecute (t , ep )
889
+ if result .Data != nil {
890
+ t .Fatalf ("wrong result, expected nil result.Data, got %v" , result .Data )
891
+ }
892
+ if ! testutil .EqualFormattedErrors (expectedErrors , result .Errors ) {
893
+ t .Fatalf ("unexpected result, Diff: %v" , testutil .Diff (expectedErrors , result .Errors ))
894
+ }
895
+ }
896
+ }
846
897
func TestUsesTheQuerySchemaForQueries (t * testing.T ) {
847
898
848
899
doc := `query Q { a } mutation M { c } subscription S { a }`
0 commit comments