/
graphql.go
70 lines (60 loc) · 1.63 KB
/
graphql.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package graphql
const (
RootQueryObjectName = "Query"
RootMutationObjectName = "Mutation"
)
const (
BasicTypeID = "ID"
BasicTypeString = "String"
BasicTypeInteger = "Int"
BasicTypeFloat = "Float"
BasicTypeBoolean = "Boolean"
BuiltInTypeAny = "Any"
BuiltInTypeMap = "Map"
BuiltInTypeTime = "Time"
)
var builtInTypes = []string{
BasicTypeID, BasicTypeString, BasicTypeInteger, BasicTypeFloat, BasicTypeBoolean, BuiltInTypeAny, BuiltInTypeMap, BuiltInTypeTime,
}
func IsCustomType(typeName string) bool {
for _, t := range builtInTypes {
if typeName == t {
return false
}
}
return true
}
type GraphQLObjectType string
const (
GraphQLObjectTypeType = GraphQLObjectType("type")
GraphQLObjectTypeInterface = GraphQLObjectType("interface")
GraphQLObjectTypeInput = GraphQLObjectType("input")
GraphQLObjectTypeScalar = GraphQLObjectType("scalar")
GraphQLObjectTypeEnum = GraphQLObjectType("enum")
)
// GraphQLObject represents type Name {...}
type GraphQLObject struct {
Name string
IsNode bool
GoModel string
ObjectType GraphQLObjectType // type, input, scalar, enum
Fields []GraphQLObjectField
Methods []GraphQLObjectMethod
Values []string // enum
}
// GraphQLObjectField represents a field in GraphQLObject
type GraphQLObjectField struct {
Name string
Type string
Nullable bool
IsArray bool
ElementNullable bool
NestDepth int
IsCustomType bool
}
// GraphQLObjectMethod represents a method in GraphQLType
type GraphQLObjectMethod struct {
Name string
Parameters []GraphQLObjectField
ReturnValue GraphQLObjectField
}