Skip to content

Commit

Permalink
invalid code generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Dunham authored and carldunham committed Oct 12, 2021
1 parent 393f755 commit acf0422
Show file tree
Hide file tree
Showing 8 changed files with 711 additions and 17 deletions.
481 changes: 481 additions & 0 deletions codegen/testserver/generated.go

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions codegen/testserver/ptr_to_ptr_input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package testserver

type PtrToPtrOuter struct {
Name string
Inner *PtrToPtrInner
StupidInner *******PtrToPtrInner
}

type PtrToPtrInner struct {
Key string
Value string
}

type UpdatePtrToPtrOuter struct {
Name *string
Inner **UpdatePtrToPtrInner
StupidInner ********UpdatePtrToPtrInner
}

type UpdatePtrToPtrInner struct {
Key *string
Value *string
}
25 changes: 25 additions & 0 deletions codegen/testserver/ptr_to_ptr_input.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type PtrToPtrOuter {
name: String!
inner: PtrToPtrInner
stupidInner: PtrToPtrInner
}

type PtrToPtrInner {
key: String!
value: String!
}

input UpdatePtrToPtrOuter {
name: String
inner: UpdatePtrToPtrInner
stupidInner: UpdatePtrToPtrInner
}

input UpdatePtrToPtrInner {
key: String
value: String
}

extend type Mutation {
updatePtrToPtr(input: UpdatePtrToPtrOuter!): PtrToPtrOuter!
}
174 changes: 174 additions & 0 deletions codegen/testserver/ptr_to_ptr_input_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package testserver

import (
"context"
"testing"

"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/stretchr/testify/require"
)

type UpdatePtrToPtrResults struct {
UpdatedPtrToPtr PtrToPtrOuter `json:"updatePtrToPtr"`
}

func TestPtrToPtr(t *testing.T) {
resolvers := &Stub{}

c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})))

resolvers.MutationResolver.UpdatePtrToPtr = func(ctx context.Context, in UpdatePtrToPtrOuter) (ret *PtrToPtrOuter, err error) {
ret = &PtrToPtrOuter{
Name: "oldName",
Inner: &PtrToPtrInner{
Key: "oldKey",
Value: "oldValue",
},
StupidInner: nest7(&PtrToPtrInner{
Key: "oldStupidKey",
Value: "oldStupidValue",
}),
}

if in.Name != nil {
ret.Name = *in.Name
}

if in.Inner != nil {
inner := *in.Inner
if inner == nil {
ret.Inner = nil
} else {
if in.Inner == nil {
ret.Inner = &PtrToPtrInner{}
}
if inner.Key != nil {
ret.Inner.Key = *inner.Key
}
if inner.Value != nil {
ret.Inner.Value = *inner.Value
}
}
}

if in.StupidInner != nil {
si := *in.StupidInner
if si == nil {
ret.StupidInner = nil
} else {
deepIn := ******si
deepOut := ******ret.StupidInner
if deepIn.Key != nil {
deepOut.Key = *deepIn.Key
}
if deepIn.Value != nil {
deepOut.Value = *deepIn.Value
}
}
}
return
}

t.Run("pointer to pointer input missing", func(t *testing.T) {
var resp UpdatePtrToPtrResults

err := c.Post(`mutation { updatePtrToPtr(input: { name: "newName" }) { name, inner { key, value }, stupidInner { key, value }}}`, &resp)
require.NoError(t, err)

require.Equal(t, resp.UpdatedPtrToPtr.Name, "newName")
require.NotNil(t, resp.UpdatedPtrToPtr.Inner)
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Key, "oldKey")
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Value, "oldValue")
require.NotNil(t, resp.UpdatedPtrToPtr.StupidInner)
require.NotNil(t, ******resp.UpdatedPtrToPtr.StupidInner)
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Key, "oldStupidKey")
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Value, "oldStupidValue")
})

t.Run("pointer to pointer input non-null", func(t *testing.T) {
var resp UpdatePtrToPtrResults

err := c.Post(`mutation {
updatePtrToPtr(input: {
inner: {
key: "newKey"
value: "newValue"
}
})
{ name, inner { key, value }, stupidInner { key, value }}
}`, &resp)
require.NoError(t, err)

require.Equal(t, resp.UpdatedPtrToPtr.Name, "oldName")
require.NotNil(t, resp.UpdatedPtrToPtr.Inner)
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Key, "newKey")
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Value, "newValue")
require.NotNil(t, resp.UpdatedPtrToPtr.StupidInner)
require.NotNil(t, ******resp.UpdatedPtrToPtr.StupidInner)
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Key, "oldStupidKey")
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Value, "oldStupidValue")
})

t.Run("pointer to pointer input null", func(t *testing.T) {
var resp UpdatePtrToPtrResults

err := c.Post(`mutation { updatePtrToPtr(input: { inner: null }) { name, inner { key, value }, stupidInner { key, value }}}`, &resp)
require.NoError(t, err)

require.Equal(t, resp.UpdatedPtrToPtr.Name, "oldName")
require.Nil(t, resp.UpdatedPtrToPtr.Inner)
require.NotNil(t, resp.UpdatedPtrToPtr.StupidInner)
require.NotNil(t, ******resp.UpdatedPtrToPtr.StupidInner)
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Key, "oldStupidKey")
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Value, "oldStupidValue")
})

t.Run("many pointers input non-null", func(t *testing.T) {
var resp UpdatePtrToPtrResults

err := c.Post(`mutation {
updatePtrToPtr(input: {
stupidInner: {
key: "newKey"
value: "newValue"
}
})
{ name, inner { key, value }, stupidInner { key, value }}
}`, &resp)
require.NoError(t, err)

require.Equal(t, resp.UpdatedPtrToPtr.Name, "oldName")
require.NotNil(t, resp.UpdatedPtrToPtr.Inner)
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Key, "oldKey")
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Value, "oldValue")
require.NotNil(t, resp.UpdatedPtrToPtr.StupidInner)
require.NotNil(t, ******resp.UpdatedPtrToPtr.StupidInner)
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Key, "newKey")
require.Equal(t, (******resp.UpdatedPtrToPtr.StupidInner).Value, "newValue")
})

t.Run("many pointers input null", func(t *testing.T) {
var resp UpdatePtrToPtrResults

err := c.Post(`mutation { updatePtrToPtr(input: { stupidInner: null }) { name, inner { key, value }, stupidInner { key, value }}}`, &resp)
require.NoError(t, err)

require.Equal(t, resp.UpdatedPtrToPtr.Name, "oldName")
require.NotNil(t, resp.UpdatedPtrToPtr.Inner)
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Key, "oldKey")
require.Equal(t, resp.UpdatedPtrToPtr.Inner.Value, "oldValue")
require.Nil(t, resp.UpdatedPtrToPtr.StupidInner)
})
}

func nest7(in *PtrToPtrInner) *******PtrToPtrInner {
si2 := &in
si3 := &si2
si4 := &si3
si5 := &si4
si6 := &si5
si7 := &si6

return si7
}
4 changes: 4 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (r *mutationResolver) UpdateSomething(ctx context.Context, input SpecialInp
panic("not implemented")
}

func (r *mutationResolver) UpdatePtrToPtr(ctx context.Context, input UpdatePtrToPtrOuter) (*PtrToPtrOuter, error) {
panic("not implemented")
}

func (r *overlappingFieldsResolver) OldFoo(ctx context.Context, obj *OverlappingFields) (int, error) {
panic("not implemented")
}
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,12 @@ require (
)

require (
github.com/agnivade/levenshtein v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/logrusorgru/aurora/v3 v3.0.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect
)
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@ require (
require (
github.com/agnivade/levenshtein v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)

0 comments on commit acf0422

Please sign in to comment.