5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-25 12:11:35 +00:00
matterbridge/vendor/github.com/graph-gophers/graphql-go/id.go

31 lines
582 B
Go
Raw Normal View History

2022-03-31 22:23:19 +00:00
package graphql
import (
"fmt"
"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 = fmt.Errorf("wrong type for ID: %T", input)
}
return err
}
func (id ID) MarshalJSON() ([]byte, error) {
return strconv.AppendQuote(nil, string(id)), nil
}