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

Function queriesFor

script/ghmock/scaffold.go:177–203  ·  view source on GitHub ↗

queriesFor returns the queries gh sent for a GraphQL request in the most recent run that sent it, once each. Comparing versions can send more than one, and a stored response needs the fields of all of them.

(entries []loggedRequest, name string)

Source from the content-addressed store, hash-verified

175// recent run that sent it, once each. Comparing versions can send more than
176// one, and a stored response needs the fields of all of them.
177func queriesFor(entries []loggedRequest, name string) []sentQuery {
178 last := -1
179 for i, entrie := range slices.Backward(entries) {
180 if entrie.Name == name && entrie.GraphQL != nil {
181 last = i
182 break
183 }
184 }
185 if last < 0 {
186 return nil
187 }
188 run := entries[last].Run
189 seen := map[string]bool{}
190 var queries []sentQuery
191 for _, e := range entries {
192 if e.Run != run || e.Name != name || e.GraphQL == nil {
193 continue
194 }
195 key := e.GraphQL.Query + "\x00" + compactJSON(e.GraphQL.Variables)
196 if seen[key] {
197 continue
198 }
199 seen[key] = true
200 queries = append(queries, sentQuery{e.GraphQL.Query, e.GraphQL.Variables})
201 }
202 return queries
203}
204
205// scaffoldGraphQL adds a response built from gh's query, or adds the fields
206// gh asked for to stored responses that lack them. explicit is true when the

Callers 1

scaffoldGraphQLFunction · 0.85

Calls 1

compactJSONFunction · 0.70

Tested by

no test coverage detected