Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2485 for some types requiring a scalar #2508

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _examples/scalars/external/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package external
type (
ObjectID int
Manufacturer string // remote named string
Count uint32 // remote named uint32
)

const (
Expand Down
240 changes: 240 additions & 0 deletions _examples/scalars/generated.go

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

4 changes: 4 additions & 0 deletions _examples/scalars/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type (
Banned bool
LoginBanned bool
QueryBanned = bool
Sum uint16 // local named uint16
)

func (b Banned) MarshalGQL(w io.Writer) {
Expand Down Expand Up @@ -52,6 +53,9 @@ type User struct {
Address Address
Tier Tier
CarManufacturer external.Manufacturer
Children uint
Cars external.Count
Weddings Sum
}

// Point is serialized as a simple array, eg [1, 2]
Expand Down
3 changes: 3 additions & 0 deletions _examples/scalars/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (r *queryResolver) User(ctx context.Context, id external.ObjectID) (*model.
CarManufacturer: external.ManufacturerTesla,
IsLoginBanned: true,
IsQueryBanned: true,
Children: 3,
Cars: 5,
Weddings: 2,
}, nil
}

Expand Down
13 changes: 13 additions & 0 deletions _examples/scalars/scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type RawUser struct {
IsBanned bool
IsLoginBanned bool
IsQueryBanned bool
Children int
Cars int
Weddings int
}

func TestScalars(t *testing.T) {
Expand Down Expand Up @@ -77,6 +80,16 @@ func TestScalars(t *testing.T) {
require.Equal(t, true, resp.User.IsQueryBanned)
})

t.Run("unusual basic", func(t *testing.T) {
var resp struct{ User RawUser }

err := c.Post(`{ user(id:"=1=") { children cars weddings } }`, &resp)
require.NoError(t, err)
require.Equal(t, 3, resp.User.Children)
require.Equal(t, 5, resp.User.Cars)
require.Equal(t, 2, resp.User.Weddings)
})

t.Run("custom error messages", func(t *testing.T) {
var resp struct{ Search []RawUser }

Expand Down
3 changes: 3 additions & 0 deletions _examples/scalars/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type User {
address: Address
tier: Tier
carManufacturer: String!
children: Int!
cars: Int!
weddings: Int!
}

type Address {
Expand Down
Loading