(w io.Writer, schema *ast.Schema, def *ast.Definition)
| 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)) |
| 106 | writeDescription(w, def.Description) |
| 107 | switch def.Kind { |
| 108 | case ast.Object, ast.Interface: |
| 109 | if len(def.Interfaces) > 0 { |
| 110 | fmt.Fprintf(w, "Implements: %s\n", strings.Join(sortedCopy(def.Interfaces), ", ")) |
| 111 | } |
| 112 | if def.Kind == ast.Interface { |
| 113 | fmt.Fprintf(w, "Implemented by: %s\n", strings.Join(sortedCopy(possibleTypeNames(schema, def)), ", ")) |
| 114 | } |
| 115 | fmt.Fprintln(w, "Fields (a type ending in ! is never null):") |
| 116 | writeGraphQLFields(w, def.Fields) |
| 117 | case ast.InputObject: |
| 118 | fmt.Fprintln(w, "Fields (a type ending in ! is required):") |
| 119 | writeGraphQLFields(w, def.Fields) |
| 120 | case ast.Union: |
| 121 | fmt.Fprintf(w, "Can be: %s\n", strings.Join(sortedCopy(possibleTypeNames(schema, def)), ", ")) |
| 122 | case ast.Enum: |
| 123 | fmt.Fprintln(w, "Values:") |
| 124 | width := 0 |
| 125 | for _, v := range def.EnumValues { |
| 126 | width = max(width, len(v.Name)) |
| 127 | } |
| 128 | for _, v := range def.EnumValues { |
| 129 | line := " " + v.Name |
| 130 | if d := firstLine(v.Description); d != "" { |
| 131 | line += strings.Repeat(" ", width-len(v.Name)+2) + d |
| 132 | } |
| 133 | if v.Directives.ForName("deprecated") != nil { |
| 134 | line += " (deprecated)" |
| 135 | } |
| 136 | fmt.Fprintln(w, line) |
| 137 | } |
| 138 | case ast.Scalar: |
| 139 | fmt.Fprintf(w, "Sent as %s.\n", scalarJSON(def.Name)) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | func writeGraphQLFields(w io.Writer, fields ast.FieldList) { |
| 144 | for _, f := range fields { |
no test coverage detected