-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
05500c9
commit 026c9dc
Showing
9 changed files
with
6 additions
and
526 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,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) | ||
} | ||
} |
Oops, something went wrong.