Skip to content

Commit

Permalink
fix #2485 for some types requiring a scalar (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstephano committed Jan 16, 2023
1 parent 11c3a4d commit ec3b471
Show file tree
Hide file tree
Showing 14 changed files with 887 additions and 33 deletions.
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

0 comments on commit ec3b471

Please sign in to comment.