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

Function writeGraphQLType

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

Source from the content-addressed store, hash-verified

102}
103
104func writeGraphQLType(w io.Writer, schema *ast.Schema, def *ast.Definition) {
105 fmt.Fprintf(w, "%s: %s\n", def.Name, kindLabel(def.Kind))
106 writeDescription(w, def.Description)
107 switch def.Kind {
108 case ast.Object, ast.Interface:
109 if len(def.Interfaces) > 0 {
110 fmt.Fprintf(w, "Implements: %s\n", strings.Join(sortedCopy(def.Interfaces), ", "))
111 }
112 if def.Kind == ast.Interface {
113 fmt.Fprintf(w, "Implemented by: %s\n", strings.Join(sortedCopy(possibleTypeNames(schema, def)), ", "))
114 }
115 fmt.Fprintln(w, "Fields (a type ending in ! is never null):")
116 writeGraphQLFields(w, def.Fields)
117 case ast.InputObject:
118 fmt.Fprintln(w, "Fields (a type ending in ! is required):")
119 writeGraphQLFields(w, def.Fields)
120 case ast.Union:
121 fmt.Fprintf(w, "Can be: %s\n", strings.Join(sortedCopy(possibleTypeNames(schema, def)), ", "))
122 case ast.Enum:
123 fmt.Fprintln(w, "Values:")
124 width := 0
125 for _, v := range def.EnumValues {
126 width = max(width, len(v.Name))
127 }
128 for _, v := range def.EnumValues {
129 line := " " + v.Name
130 if d := firstLine(v.Description); d != "" {
131 line += strings.Repeat(" ", width-len(v.Name)+2) + d
132 }
133 if v.Directives.ForName("deprecated") != nil {
134 line += " (deprecated)"
135 }
136 fmt.Fprintln(w, line)
137 }
138 case ast.Scalar:
139 fmt.Fprintf(w, "Sent as %s.\n", scalarJSON(def.Name))
140 }
141}
142
143func writeGraphQLFields(w io.Writer, fields ast.FieldList) {
144 for _, f := range fields {

Callers 1

describeGraphQLFunction · 0.85

Calls 8

kindLabelFunction · 0.85
writeDescriptionFunction · 0.85
sortedCopyFunction · 0.85
possibleTypeNamesFunction · 0.85
writeGraphQLFieldsFunction · 0.85
scalarJSONFunction · 0.85
JoinMethod · 0.80
firstLineFunction · 0.70

Tested by

no test coverage detected