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

Method mergeIntrospection

script/ghmock/introspection.go:40–107  ·  view source on GitHub ↗
(path string, existing, resolved any, sel ast.SelectionSet, record bool)

Source from the content-addressed store, hash-verified

38}
39
40func (s *gqlScaffolder) mergeIntrospection(path string, existing, resolved any, sel ast.SelectionSet, record bool) any {
41 switch source := resolved.(type) {
42 case introObject:
43 dst, ok := existing.(map[string]any)
44 if !ok {
45 return existing
46 }
47 var keys []string
48 groups := map[string][]*ast.Field{}
49 s.collect(sel, s.schema.Types[source.typeName()], &keys, groups)
50 for _, key := range keys {
51 field := groups[key][0]
52 child := path + "." + key
53 value := source.resolve(s, field.Name, s.arguments(field))
54 if field.Name == "__typename" {
55 value = source.typeName()
56 }
57 selections := mergeSelections(groups[key])
58 if previous, found := dst[key]; found {
59 dst[key] = s.mergeIntrospection(child, previous, value, selections, record)
60 } else {
61 dst[key] = s.introValue(value, selections)
62 if record {
63 s.added = append(s.added, child)
64 }
65 }
66 }
67 case []introObject:
68 dst, ok := existing.([]any)
69 if !ok {
70 return existing
71 }
72 nameKeys := []string{"name"}
73 if len(source) > 0 {
74 var keys []string
75 groups := map[string][]*ast.Field{}
76 s.collect(sel, s.schema.Types[source[0].typeName()], &keys, groups)
77 for _, key := range keys {
78 if groups[key][0].Name == "name" && key != "name" {
79 nameKeys = append(nameKeys, key)
80 }
81 }
82 }
83 for i, value := range dst {
84 index := i
85 if object, ok := value.(map[string]any); ok {
86 for _, key := range nameKeys {
87 name, ok := object[key].(string)
88 if !ok {
89 continue
90 }
91 index = -1
92 for j, candidate := range source {
93 if candidate.resolve(s, "name", nil) == name {
94 index = j
95 break
96 }
97 }

Callers 1

fillObjectMethod · 0.95

Calls 6

collectMethod · 0.95
argumentsMethod · 0.95
introValueMethod · 0.95
mergeSelectionsFunction · 0.85
typeNameMethod · 0.65
resolveMethod · 0.65

Tested by

no test coverage detected