mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
567 B
31 lines
567 B
6 years ago
|
package graphql
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
// ID represents GraphQL's "ID" scalar type. A custom type may be used instead.
|
||
|
type ID string
|
||
|
|
||
|
func (ID) ImplementsGraphQLType(name string) bool {
|
||
|
return name == "ID"
|
||
|
}
|
||
|
|
||
|
func (id *ID) UnmarshalGraphQL(input interface{}) error {
|
||
|
var err error
|
||
|
switch input := input.(type) {
|
||
|
case string:
|
||
|
*id = ID(input)
|
||
|
case int32:
|
||
|
*id = ID(strconv.Itoa(int(input)))
|
||
|
default:
|
||
|
err = errors.New("wrong type")
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (id ID) MarshalJSON() ([]byte, error) {
|
||
|
return strconv.AppendQuote(nil, string(id)), nil
|
||
|
}
|