-
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.
Merge pull request #588 from 99designs/fix-default-scalar-implementat…
…ion-regression Fix default scalar implementation regression
- Loading branch information
Showing
6 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extend type Query { | ||
defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! | ||
} | ||
|
||
""" This doesnt have an implementation in the typemap, so it should act like a string """ | ||
scalar DefaultScalarImplementation |
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,34 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaultScalarImplementation(t *testing.T) { | ||
resolvers := &Stub{} | ||
|
||
srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) | ||
c := client.New(srv.URL) | ||
|
||
resolvers.QueryResolver.DefaultScalar = func(ctx context.Context, arg string) (i string, e error) { | ||
return arg, nil | ||
} | ||
|
||
t.Run("with arg value", func(t *testing.T) { | ||
var resp struct{ DefaultScalar string } | ||
c.MustPost(`query { defaultScalar(arg: "fff") }`, &resp) | ||
require.Equal(t, "fff", resp.DefaultScalar) | ||
}) | ||
|
||
t.Run("with default value", func(t *testing.T) { | ||
var resp struct{ DefaultScalar string } | ||
c.MustPost(`query { defaultScalar }`, &resp) | ||
require.Equal(t, "default", resp.DefaultScalar) | ||
}) | ||
} |
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