github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/embedded_test.go (about) 1 package followschema 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/operandinc/gqlgen/client" 8 "github.com/operandinc/gqlgen/graphql/handler" 9 "github.com/stretchr/testify/require" 10 ) 11 12 type fakeUnexportedEmbeddedInterface struct{} 13 14 func (*fakeUnexportedEmbeddedInterface) UnexportedEmbeddedInterfaceExportedMethod() string { 15 return "UnexportedEmbeddedInterfaceExportedMethod" 16 } 17 18 func TestEmbedded(t *testing.T) { 19 resolver := &Stub{} 20 resolver.QueryResolver.EmbeddedCase1 = func(ctx context.Context) (*EmbeddedCase1, error) { 21 return &EmbeddedCase1{}, nil 22 } 23 resolver.QueryResolver.EmbeddedCase2 = func(ctx context.Context) (*EmbeddedCase2, error) { 24 return &EmbeddedCase2{&unexportedEmbeddedPointer{}}, nil 25 } 26 resolver.QueryResolver.EmbeddedCase3 = func(ctx context.Context) (*EmbeddedCase3, error) { 27 return &EmbeddedCase3{&fakeUnexportedEmbeddedInterface{}}, nil 28 } 29 30 c := client.New(handler.NewDefaultServer( 31 NewExecutableSchema(Config{Resolvers: resolver}), 32 )) 33 34 t.Run("embedded case 1", func(t *testing.T) { 35 var resp struct { 36 EmbeddedCase1 struct { 37 ExportedEmbeddedPointerExportedMethod string 38 } 39 } 40 err := c.Post(`query { embeddedCase1 { exportedEmbeddedPointerExportedMethod } }`, &resp) 41 require.NoError(t, err) 42 require.Equal(t, resp.EmbeddedCase1.ExportedEmbeddedPointerExportedMethod, "ExportedEmbeddedPointerExportedMethodResponse") 43 }) 44 45 t.Run("embedded case 2", func(t *testing.T) { 46 var resp struct { 47 EmbeddedCase2 struct { 48 UnexportedEmbeddedPointerExportedMethod string 49 } 50 } 51 err := c.Post(`query { embeddedCase2 { unexportedEmbeddedPointerExportedMethod } }`, &resp) 52 require.NoError(t, err) 53 require.Equal(t, resp.EmbeddedCase2.UnexportedEmbeddedPointerExportedMethod, "UnexportedEmbeddedPointerExportedMethodResponse") 54 }) 55 56 t.Run("embedded case 3", func(t *testing.T) { 57 var resp struct { 58 EmbeddedCase3 struct { 59 UnexportedEmbeddedInterfaceExportedMethod string 60 } 61 } 62 err := c.Post(`query { embeddedCase3 { unexportedEmbeddedInterfaceExportedMethod } }`, &resp) 63 require.NoError(t, err) 64 require.Equal(t, resp.EmbeddedCase3.UnexportedEmbeddedInterfaceExportedMethod, "UnexportedEmbeddedInterfaceExportedMethod") 65 }) 66 }