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

Function exclusiveTypeConflict

script/ghmock/graphqlcheck.go:68–120  ·  view source on GitHub ↗
(schema *ast.Schema, doc *ast.QueryDocument, problem *gqlerror.Error)

Source from the content-addressed store, hash-verified

66}
67
68func exclusiveTypeConflict(schema *ast.Schema, doc *ast.QueryDocument, problem *gqlerror.Error) bool {
69 if problem.Rule != validatorrules.OverlappingFieldsCanBeMergedRule.Name ||
70 !strings.Contains(problem.Message, "conflicting types") || len(problem.Locations) != 1 {
71 return false
72 }
73 var fields []*ast.Field
74 var second *ast.Field
75 var collect func(ast.SelectionSet)
76 collect = func(sel ast.SelectionSet) {
77 for _, item := range sel {
78 switch field := item.(type) {
79 case *ast.Field:
80 fields = append(fields, field)
81 if (gqlerror.Location{Line: field.Position.Line, Column: field.Position.Column}) == problem.Locations[0] {
82 second = field
83 }
84 collect(field.SelectionSet)
85 case *ast.InlineFragment:
86 collect(field.SelectionSet)
87 }
88 }
89 }
90 for _, op := range doc.Operations {
91 collect(op.SelectionSet)
92 }
93 for _, fragment := range doc.Fragments {
94 collect(fragment.SelectionSet)
95 }
96 if second == nil || second.Definition == nil || second.ObjectDefinition.Kind != ast.Object ||
97 !schema.Types[second.Definition.Type.Name()].IsLeafType() {
98 return false
99 }
100 matched := false
101 for _, first := range fields {
102 if first == second || first.Definition == nil || first.Alias != second.Alias {
103 continue
104 }
105 message := fmt.Sprintf(
106 "Fields %q conflict because they return conflicting types %q and %q. Use different aliases on the fields to fetch both if this was intentional.",
107 first.Alias, first.Definition.Type.String(), second.Definition.Type.String())
108 if message != problem.Message {
109 continue
110 }
111 // The pinned validator reports only the second field's location. Every
112 // possible match must be the concrete-type exception, not an interface.
113 if first.ObjectDefinition.Kind != ast.Object || first.ObjectDefinition.Name == second.ObjectDefinition.Name ||
114 !schema.Types[first.Definition.Type.Name()].IsLeafType() {
115 return false
116 }
117 matched = true
118 }
119 return matched
120}
121
122func graphQLErrorText(err error) string {
123 if ge, ok := errors.AsType[*gqlerror.Error](err); ok {

Callers 1

checkGraphQLQueryFunction · 0.85

Calls 3

ContainsMethod · 0.80
NameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected