-
Notifications
You must be signed in to change notification settings - Fork 4
/
scalar.go
31 lines (28 loc) · 864 Bytes
/
scalar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package graphqlmultipart
import (
"fmt"
"mime/multipart"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/language/ast"
)
// Upload is a scalar represents a uploaded file using \"multipart/form-data\" as described in the graphql multipart spec
var Upload = graphql.NewScalar(graphql.ScalarConfig{
Name: "Upload",
Description: fmt.Sprintf("The `Upload` scalar represents a uploaded file using \"multipart/form-data\" as described in the spec: (%s)", specURL),
Serialize: func(v interface{}) interface{} {
panic("cannot serialize upload type")
},
ParseValue: func(v interface{}) interface{} {
switch v.(type) {
case *multipart.FileHeader:
return v
case multipart.FileHeader:
return v
default:
return nil
}
},
ParseLiteral: func(valueAST ast.Value) interface{} {
panic("cannot parse a upload literal")
},
})