@@ -297,6 +297,62 @@ func TestMergesParallelFragments(t *testing.T) {
297297 }
298298}
299299
300+ type CustomMap map [string ]interface {}
301+
302+ func TestCustomMapType (t * testing.T ) {
303+ query := `
304+ query Example { data { a } }
305+ `
306+ data := CustomMap {
307+ "a" : "1" ,
308+ "b" : "2" ,
309+ }
310+ schema , err := graphql .NewSchema (graphql.SchemaConfig {
311+ Query : graphql .NewObject (graphql.ObjectConfig {
312+ Name : "RootQuery" ,
313+ Fields : graphql.Fields {
314+ "data" : & graphql.Field {
315+ Type : graphql .NewObject (graphql.ObjectConfig {
316+ Name : "Data" ,
317+ Fields : graphql.Fields {
318+ "a" : & graphql.Field {
319+ Type : graphql .String ,
320+ },
321+ "b" : & graphql.Field {
322+ Type : graphql .String ,
323+ },
324+ },
325+ }),
326+ Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
327+ return data , nil
328+ },
329+ },
330+ },
331+ }),
332+ })
333+ if err != nil {
334+ t .Fatalf ("Error in schema %v" , err .Error ())
335+ }
336+
337+ result := testutil .TestExecute (t , graphql.ExecuteParams {
338+ Schema : schema ,
339+ Root : data ,
340+ AST : testutil .TestParse (t , query ),
341+ })
342+ if len (result .Errors ) > 0 {
343+ t .Fatalf ("wrong result, unexpected errors: %v" , result .Errors )
344+ }
345+
346+ expected := map [string ]interface {}{
347+ "data" : map [string ]interface {}{
348+ "a" : "1" ,
349+ },
350+ }
351+ if ! reflect .DeepEqual (result .Data , expected ) {
352+ t .Fatalf ("Expected context.key to equal %v, got %v" , expected , result .Data )
353+ }
354+ }
355+
300356func TestThreadsSourceCorrectly (t * testing.T ) {
301357
302358 query := `
@@ -843,6 +899,57 @@ func TestThrowsIfUnknownOperationNameIsProvided(t *testing.T) {
843899 t .Fatalf ("unexpected result, Diff: %v" , testutil .Diff (expectedErrors , result .Errors ))
844900 }
845901}
902+
903+ func TestThrowsIfOperationTypeIsUnsupported (t * testing.T ) {
904+ query := `mutation Mut { a } subscription Sub { a }`
905+ operations := []string {"Mut" , "Sub" }
906+
907+ expectedErrors := [][]gqlerrors.FormattedError {
908+ {{
909+ Message : `Schema is not configured for mutations` ,
910+ Locations : []location.SourceLocation {{Line : 1 , Column : 1 }},
911+ }},
912+ {{
913+ Message : `Schema is not configured for subscriptions` ,
914+ Locations : []location.SourceLocation {{Line : 1 , Column : 20 }},
915+ }},
916+ }
917+
918+ schema , err := graphql .NewSchema (graphql.SchemaConfig {
919+ Query : graphql .NewObject (graphql.ObjectConfig {
920+ Name : "Query" ,
921+ Fields : graphql.Fields {
922+ "a" : & graphql.Field {
923+ Type : graphql .String ,
924+ },
925+ },
926+ }),
927+ })
928+ if err != nil {
929+ t .Fatalf ("Error in schema %v" , err .Error ())
930+ }
931+
932+ // parse query
933+ ast := testutil .TestParse (t , query )
934+
935+ for opIndex , operation := range operations {
936+ expectedErrors := expectedErrors [opIndex ]
937+
938+ // execute
939+ ep := graphql.ExecuteParams {
940+ Schema : schema ,
941+ AST : ast ,
942+ OperationName : operation ,
943+ }
944+ result := testutil .TestExecute (t , ep )
945+ if result .Data != nil {
946+ t .Fatalf ("wrong result, expected nil result.Data, got %v" , result .Data )
947+ }
948+ if ! testutil .EqualFormattedErrors (expectedErrors , result .Errors ) {
949+ t .Fatalf ("unexpected result, Diff: %v" , testutil .Diff (expectedErrors , result .Errors ))
950+ }
951+ }
952+ }
846953func TestUsesTheQuerySchemaForQueries (t * testing.T ) {
847954
848955 doc := `query Q { a } mutation M { c } subscription S { a }`
0 commit comments