MCPcopy Create free account
hub / github.com/cli/cli / writeGraphQLField

Function writeGraphQLField

script/ghmock/schemacmd.go:156–181  ·  view source on GitHub ↗
(w io.Writer, schema *ast.Schema, def *ast.Definition, f *ast.FieldDefinition)

Source from the content-addressed store, hash-verified

154}
155
156func writeGraphQLField(w io.Writer, schema *ast.Schema, def *ast.Definition, f *ast.FieldDefinition) {
157 input := def.Kind == ast.InputObject
158 fmt.Fprintf(w, "%s.%s: %s\n", def.Name, f.Name, f.Type.String())
159 fmt.Fprintln(w, nullability(f.Type, input))
160 writeDescription(w, f.Description)
161 if d := f.Directives.ForName("deprecated"); d != nil {
162 reason := "No longer supported"
163 if arg := d.Arguments.ForName("reason"); arg != nil && arg.Value != nil {
164 reason = arg.Value.Raw
165 }
166 fmt.Fprintf(w, "Deprecated: %s\n", firstLine(reason))
167 }
168 if len(f.Arguments) > 0 {
169 fmt.Fprintln(w, "Arguments (a type ending in ! is required):")
170 for _, a := range f.Arguments {
171 line := fmt.Sprintf(" %s: %s", a.Name, a.Type.String())
172 if a.DefaultValue != nil {
173 line += " = " + a.DefaultValue.String()
174 }
175 fmt.Fprintln(w, line)
176 }
177 }
178 if t := schema.Types[f.Type.Name()]; t != nil && t.Kind != ast.Scalar {
179 fmt.Fprintf(w, "See also: ghmock schema %s\n", t.Name)
180 }
181}
182
183// nullability says whether a field's value can be null, or for input fields,
184// whether the field is required.

Callers 1

describeGraphQLFunction · 0.85

Calls 5

nullabilityFunction · 0.85
writeDescriptionFunction · 0.85
firstLineFunction · 0.70
StringMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected