-
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 tests for defined types as []byte and []rune
- Loading branch information
Showing
9 changed files
with
242 additions
and
7 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,60 @@ | ||
package external | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
) | ||
|
||
type ( | ||
ObjectID int | ||
Manufacturer string // remote named string | ||
Count uint8 // remote named uint8 | ||
ObjectID int | ||
Manufacturer string // remote named string | ||
Count uint8 // remote named uint8 | ||
ExternalBytes []byte | ||
ExternalRunes []rune | ||
) | ||
|
||
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) | ||
} | ||
} |
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
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
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