• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

99designs / gqlgen / 12999394514

27 Jan 2025 10:16PM UTC coverage: 73.738% (-0.2%) from 73.891%
12999394514

Pull #3507

github

StevenACoffman
Regenerate

Signed-off-by: Steve Coffman <steve@khanacademy.org>
Pull Request #3507: Update gqlparser v2 to v2.5.22 to Support `@oneOf` and `@deprecated` on input values

4 of 27 new or added lines in 3 files covered. (14.81%)

2 existing lines in 1 file now uncovered.

8617 of 11686 relevant lines covered (73.74%)

545.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.44
/graphql/introspection/type.go
1
package introspection
2

3
import (
4
        "strings"
5

6
        "github.com/vektah/gqlparser/v2/ast"
7
)
8

9
type Type struct {
10
        schema *ast.Schema
11
        def    *ast.Definition
12
        typ    *ast.Type
13
}
14

15
func WrapTypeFromDef(s *ast.Schema, def *ast.Definition) *Type {
298✔
16
        if def == nil {
298✔
17
                return nil
×
18
        }
×
19
        return &Type{schema: s, def: def}
298✔
20
}
21

22
func WrapTypeFromType(s *ast.Schema, typ *ast.Type) *Type {
1,441✔
23
        if typ == nil {
1,444✔
24
                return nil
3✔
25
        }
3✔
26

27
        if !typ.NonNull && typ.NamedType != "" {
2,262✔
28
                return &Type{schema: s, def: s.Types[typ.NamedType]}
824✔
29
        }
824✔
30
        return &Type{schema: s, typ: typ}
614✔
31
}
32

33
func (t *Type) Kind() string {
1,720✔
34
        if t.typ != nil {
2,332✔
35
                if t.typ.NonNull {
1,144✔
36
                        return "NON_NULL"
532✔
37
                }
532✔
38

39
                if t.typ.Elem != nil {
160✔
40
                        return "LIST"
80✔
41
                }
80✔
42
        } else {
1,108✔
43
                return string(t.def.Kind)
1,108✔
44
        }
1,108✔
45

46
        panic("UNKNOWN")
×
47
}
48

49
func (t *Type) Name() *string {
1,733✔
50
        if t.def == nil {
2,345✔
51
                return nil
612✔
52
        }
612✔
53
        return &t.def.Name
1,121✔
54
}
55

56
func (t *Type) Description() *string {
239✔
57
        if t.def == nil || t.def.Description == "" {
459✔
58
                return nil
220✔
59
        }
220✔
60
        return &t.def.Description
19✔
61
}
62

63
func (t *Type) Fields(includeDeprecated bool) []Field {
242✔
64
        if t.def == nil || (t.def.Kind != ast.Object && t.def.Kind != ast.Interface) {
328✔
65
                return []Field{}
86✔
66
        }
86✔
67
        fields := []Field{}
156✔
68
        for _, f := range t.def.Fields {
684✔
69
                if strings.HasPrefix(f.Name, "__") {
534✔
70
                        continue
6✔
71
                }
72

73
                if !includeDeprecated && f.Directives.ForName("deprecated") != nil {
523✔
74
                        continue
1✔
75
                }
76

77
                var args []InputValue
521✔
78
                for _, arg := range f.Arguments {
663✔
79
                        args = append(args, InputValue{
142✔
80
                                Type:         WrapTypeFromType(t.schema, arg.Type),
142✔
81
                                Name:         arg.Name,
142✔
82
                                description:  arg.Description,
142✔
83
                                DefaultValue: defaultValue(arg.DefaultValue),
142✔
84
                                deprecation:  f.Directives.ForName("deprecated"),
142✔
85
                        })
142✔
86
                }
142✔
87

88
                fields = append(fields, Field{
521✔
89
                        Name:        f.Name,
521✔
90
                        description: f.Description,
521✔
91
                        Args:        args,
521✔
92
                        Type:        WrapTypeFromType(t.schema, f.Type),
521✔
93
                        deprecation: f.Directives.ForName("deprecated"),
521✔
94
                })
521✔
95
        }
96
        return fields
156✔
97
}
98

99
func (t *Type) InputFields() []InputValue {
238✔
100
        if t.def == nil || t.def.Kind != ast.InputObject {
440✔
101
                return []InputValue{}
202✔
102
        }
202✔
103

104
        res := []InputValue{}
36✔
105
        for _, f := range t.def.Fields {
162✔
106
                res = append(res, InputValue{
126✔
107
                        Name:         f.Name,
126✔
108
                        description:  f.Description,
126✔
109
                        Type:         WrapTypeFromType(t.schema, f.Type),
126✔
110
                        DefaultValue: defaultValue(f.DefaultValue),
126✔
111
                        deprecation:  f.Directives.ForName("deprecated"),
126✔
112
                })
126✔
113
        }
126✔
114
        return res
36✔
115
}
116

117
func defaultValue(value *ast.Value) *string {
308✔
118
        if value == nil {
586✔
119
                return nil
278✔
120
        }
278✔
121
        val := value.String()
30✔
122
        return &val
30✔
123
}
124

125
func (t *Type) Interfaces() []Type {
238✔
126
        if t.def == nil || t.def.Kind != ast.Object {
332✔
127
                return []Type{}
94✔
128
        }
94✔
129

130
        res := []Type{}
144✔
131
        for _, intf := range t.def.Interfaces {
160✔
132
                res = append(res, *WrapTypeFromDef(t.schema, t.schema.Types[intf]))
16✔
133
        }
16✔
134

135
        return res
144✔
136
}
137

138
func (t *Type) PossibleTypes() []Type {
238✔
139
        if t.def == nil || (t.def.Kind != ast.Interface && t.def.Kind != ast.Union) {
462✔
140
                return []Type{}
224✔
141
        }
224✔
142

143
        res := []Type{}
14✔
144
        for _, pt := range t.schema.GetPossibleTypes(t.def) {
44✔
145
                res = append(res, *WrapTypeFromDef(t.schema, pt))
30✔
146
        }
30✔
147
        return res
14✔
148
}
149

150
func (t *Type) EnumValues(includeDeprecated bool) []EnumValue {
238✔
151
        if t.def == nil || t.def.Kind != ast.Enum {
466✔
152
                return []EnumValue{}
228✔
153
        }
228✔
154

155
        res := []EnumValue{}
10✔
156
        for _, val := range t.def.EnumValues {
78✔
157
                if !includeDeprecated && val.Directives.ForName("deprecated") != nil {
68✔
158
                        continue
×
159
                }
160

161
                res = append(res, EnumValue{
68✔
162
                        Name:        val.Name,
68✔
163
                        description: val.Description,
68✔
164
                        deprecation: val.Directives.ForName("deprecated"),
68✔
165
                })
68✔
166
        }
167
        return res
10✔
168
}
169

170
func (t *Type) OfType() *Type {
1,482✔
171
        if t.typ == nil {
2,352✔
172
                return nil
870✔
173
        }
870✔
174
        if t.typ.NonNull {
1,144✔
175
                // fake non null nodes
532✔
176
                cpy := *t.typ
532✔
177
                cpy.NonNull = false
532✔
178

532✔
179
                return WrapTypeFromType(t.schema, &cpy)
532✔
180
        }
532✔
181
        return WrapTypeFromType(t.schema, t.typ.Elem)
80✔
182
}
183

184
func (t *Type) SpecifiedByURL() *string {
238✔
185
        if t.def == nil {
238✔
NEW
186
                return nil
×
NEW
187
        }
×
188
        directive := t.def.Directives.ForName("specifiedBy")
238✔
189
        if t.def.Kind != ast.Scalar || directive == nil {
476✔
190
                return nil
238✔
191
        }
238✔
192
        // def: directive @specifiedBy(url: String!) on SCALAR
193
        // the argument "url" is required.
194
        url := directive.Arguments.ForName("url")
×
195
        return &url.Value.Raw
×
196
}
197

NEW
198
func (t *Type) IsOneOf() bool {
×
NEW
199
        if t.def == nil {
×
NEW
200
                return false
×
NEW
201
        }
×
NEW
202
        directive := t.def.Directives.ForName("oneOf")
×
NEW
203
        if t.def.Kind != ast.InputObject || directive == nil {
×
NEW
204
                return false
×
NEW
205
        }
×
NEW
206
        return true
×
207
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc