Skip to content

Commit

Permalink
Revert "fix #2524 basic alias Byte was not binded properly (#2528)" (#…
Browse files Browse the repository at this point in the history
…2586)

This reverts commit 5b85e93.
  • Loading branch information
StevenACoffman authored Mar 20, 2023
1 parent 05500c9 commit 026c9dc
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 526 deletions.
8 changes: 0 additions & 8 deletions _examples/scalars/.gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ models:
model: github.com/99designs/gqlgen/_examples/scalars/model.Banned
DarkMode:
model: github.com/99designs/gqlgen/_examples/scalars/model.Preferences
Bytes:
model: "github.com/99designs/gqlgen/codegen/testserver/singlefile.Bytes"
Runes:
model: "github.com/99designs/gqlgen/_examples/scalars/model.Runes"
DefinedTypeBytes:
model: "github.com/99designs/gqlgen/_examples/scalars/external.Bytes"
DefinedTypeRunes:
model: "github.com/99designs/gqlgen/_examples/scalars/external.Runes"
53 changes: 3 additions & 50 deletions _examples/scalars/external/model.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,13 @@
package external

import (
"fmt"
"io"

"github.com/99designs/gqlgen/graphql"
)

type (
ObjectID int
Manufacturer string // remote named string
Count uint8 // remote named uint8
ExternalBytes []byte
ExternalRunes []rune
ObjectID int
Manufacturer string // remote named string
Count uint32 // remote named uint32
)

const (
ManufacturerTesla Manufacturer = "TESLA"
ManufacturerHonda Manufacturer = "HONDA"
ManufacturerToyota Manufacturer = "TOYOTA"
)

func MarshalBytes(b ExternalBytes) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = fmt.Fprintf(w, "%q", string(b))
})
}

func UnmarshalBytes(v interface{}) (ExternalBytes, error) {
switch v := v.(type) {
case string:
return ExternalBytes(v), nil
case *string:
return ExternalBytes(*v), nil
case ExternalBytes:
return v, nil
default:
return nil, fmt.Errorf("%T is not ExternalBytes", v)
}
}

func MarshalRunes(r ExternalRunes) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = fmt.Fprintf(w, "%q", string(r))
})
}

func UnmarshalRunes(v interface{}) (ExternalRunes, error) {
switch v := v.(type) {
case string:
return ExternalRunes(v), nil
case *string:
return ExternalRunes(*v), nil
case ExternalRunes:
return v, nil
default:
return nil, fmt.Errorf("%T is not ExternalRunes", v)
}
}
Loading

0 comments on commit 026c9dc

Please sign in to comment.