Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Steve Coffman <steve@khanacademy.org>
- Loading branch information
1 parent
05500c9
commit 9dbafba
Showing
16 changed files
with
105 additions
and
2,504 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,3 @@ | ||
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 | ||
) | ||
|
||
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) | ||
} | ||
} | ||
type ObjectID int |
Oops, something went wrong.