MCPcopy Index your code
hub / github.com/github/github-mcp-server / writeQuery

Function writeQuery

internal/githubv4mock/query.go:123–155  ·  view source on GitHub ↗

writeQuery writes a minified query for t to w. If inline is true, the struct fields of t are inlined into parent struct.

(w io.Writer, t reflect.Type, inline bool)

Source from the content-addressed store, hash-verified

121// writeQuery writes a minified query for t to w.
122// If inline is true, the struct fields of t are inlined into parent struct.
123func writeQuery(w io.Writer, t reflect.Type, inline bool) {
124 switch t.Kind() {
125 case reflect.Ptr, reflect.Slice:
126 writeQuery(w, t.Elem(), false)
127 case reflect.Struct:
128 // If the type implements json.Unmarshaler, it's a scalar. Don't expand it.
129 if reflect.PointerTo(t).Implements(jsonUnmarshaler) {
130 return
131 }
132 if !inline {
133 _, _ = io.WriteString(w, "{")
134 }
135 for i := 0; i < t.NumField(); i++ {
136 if i != 0 {
137 _, _ = io.WriteString(w, ",")
138 }
139 f := t.Field(i)
140 value, ok := f.Tag.Lookup("graphql")
141 inlineField := f.Anonymous && !ok
142 if !inlineField {
143 if ok {
144 _, _ = io.WriteString(w, value)
145 } else {
146 _, _ = io.WriteString(w, ident.ParseMixedCaps(f.Name).ToLowerCamelCase())
147 }
148 }
149 writeQuery(w, f.Type, inlineField)
150 }
151 if !inline {
152 _, _ = io.WriteString(w, "}")
153 }
154 }
155}
156
157var jsonUnmarshaler = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()

Callers 1

queryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected