forked from 99designs/gqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
393f755
commit acf0422
Showing
8 changed files
with
711 additions
and
17 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters