-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for aliasing different cases
fixes #376
- Loading branch information
Showing
8 changed files
with
561 additions
and
361 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
extend type Query { | ||
validType: ValidType | ||
} | ||
|
||
""" These things are all valid, but without care generate invalid go code """ | ||
type ValidType { | ||
differentCase: String! | ||
different_case: String! | ||
validInputKeywords(input: ValidInput): Boolean! | ||
validArgs( | ||
break: String!, | ||
default: String!, | ||
func: String!, | ||
interface: String!, | ||
select: String!, | ||
case: String!, | ||
defer: String!, | ||
go: String!, | ||
map: String!, | ||
struct: String!, | ||
chan: String!, | ||
else: String!, | ||
goto: String!, | ||
package: String!, | ||
switch: String!, | ||
const: String!, | ||
fallthrough: String!, | ||
if: String!, | ||
range: String!, | ||
type: String!, | ||
continue: String!, | ||
for: String!, | ||
import: String!, | ||
return: String!, | ||
var: String!, | ||
_: String!, | ||
): Boolean! | ||
} | ||
|
||
input ValidInput { | ||
break: String! | ||
default: String! | ||
func: String! | ||
interface: String! | ||
select: String! | ||
case: String! | ||
defer: String! | ||
go: String! | ||
map: String! | ||
struct: String! | ||
chan: String! | ||
else: String! | ||
goto: String! | ||
package: String! | ||
switch: String! | ||
const: String! | ||
fallthrough: String! | ||
if: String! | ||
range: String! | ||
type: String! | ||
continue: String! | ||
for: String! | ||
import: String! | ||
return: String! | ||
var: String! | ||
_: 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,38 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidType(t *testing.T) { | ||
resolvers := &Stub{} | ||
resolvers.QueryResolver.ValidType = func(ctx context.Context) (validType *ValidType, e error) { | ||
return &ValidType{ | ||
DifferentCase: "new", | ||
DifferentCaseOld: "old", | ||
}, nil | ||
} | ||
|
||
srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) | ||
c := client.New(srv.URL) | ||
|
||
t.Run("fields with differing cases can be distinguished", func(t *testing.T) { | ||
var resp struct { | ||
ValidType struct { | ||
New string `json:"differentCase"` | ||
Old string `json:"different_case"` | ||
} | ||
} | ||
err := c.Post(`query { validType { differentCase, different_case } }`, &resp) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "new", resp.ValidType.New) | ||
require.Equal(t, "old", resp.ValidType.Old) | ||
}) | ||
} |