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

Function describeGraphQL

script/ghmock/schemacmd.go:82–102  ·  view source on GitHub ↗

describeGraphQL writes what GitHub's GraphQL schema says about a type or a field.

(w io.Writer, schema *ast.Schema, name string)

Source from the content-addressed store, hash-verified

80// describeGraphQL writes what GitHub's GraphQL schema says about a type or a
81// field.
82func describeGraphQL(w io.Writer, schema *ast.Schema, name string) error {
83 typeName, fieldName, isField := strings.Cut(name, ".")
84 def := schema.Types[typeName]
85 if def == nil || strings.HasPrefix(typeName, "__") {
86 return notFound("GitHub's GraphQL schema has no type named "+typeName, typeName, graphQLTypeNames(schema))
87 }
88 if !isField {
89 writeGraphQLType(w, schema, def)
90 return nil
91 }
92 switch def.Kind {
93 case ast.Enum, ast.Union, ast.Scalar:
94 return fmt.Errorf("%s is %s, so it has no fields; ghmock schema %s describes it", def.Name, kindLabel(def.Kind), def.Name)
95 }
96 field := def.Fields.ForName(fieldName)
97 if field == nil || strings.HasPrefix(fieldName, "__") {
98 return notFound(fmt.Sprintf("%s has no field named %s", def.Name, fieldName), fieldName, graphQLFieldNames(def))
99 }
100 writeGraphQLField(w, schema, def, field)
101 return nil
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))

Callers 1

cmdSchemaFunction · 0.85

Calls 7

notFoundFunction · 0.85
graphQLTypeNamesFunction · 0.85
writeGraphQLTypeFunction · 0.85
kindLabelFunction · 0.85
graphQLFieldNamesFunction · 0.85
writeGraphQLFieldFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected