describeGraphQL writes what GitHub's GraphQL schema says about a type or a field.
(w io.Writer, schema *ast.Schema, name string)
| 80 | // describeGraphQL writes what GitHub's GraphQL schema says about a type or a |
| 81 | // field. |
| 82 | func 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 | |
| 104 | func writeGraphQLType(w io.Writer, schema *ast.Schema, def *ast.Definition) { |
| 105 | fmt.Fprintf(w, "%s: %s\n", def.Name, kindLabel(def.Kind)) |
no test coverage detected