| 28 | // const MAX_COMMENT_LEN = 80; |
| 29 | |
| 30 | export default class SchemaPlugin extends Plugin implements PluginInterface { |
| 31 | |
| 32 | getHeaders(): string[] { |
| 33 | return [ |
| 34 | '<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700" rel="stylesheet">', |
| 35 | '<link type="text/css" rel="stylesheet" href="./assets/code.css" />', |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | getAssets() { |
| 40 | return [ |
| 41 | resolve(__dirname, 'code.css') |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | getDocuments(buildForType ? : string): DocumentSectionInterface[] { |
| 46 | |
| 47 | const code = this.code(buildForType); |
| 48 | |
| 49 | if (code) |
| 50 | return [ |
| 51 | new DocumentSection('GraphQL Schema definition', html.code(code)) |
| 52 | ]; |
| 53 | |
| 54 | return []; |
| 55 | } |
| 56 | |
| 57 | code(buildForType ? : string): string { |
| 58 | |
| 59 | if (!buildForType) |
| 60 | return this.schema(this.document); |
| 61 | |
| 62 | const directive = this.document |
| 63 | .directives |
| 64 | .find((directive) => directive.name === (buildForType as string)); |
| 65 | |
| 66 | if (directive) |
| 67 | return this.directive(directive); |
| 68 | |
| 69 | const type = this.document |
| 70 | .types |
| 71 | .find((type) => type.name === (buildForType as string)); |
| 72 | |
| 73 | if (type) { |
| 74 | switch (type.kind) { |
| 75 | |
| 76 | case SCALAR: |
| 77 | return this.scalar(type); |
| 78 | |
| 79 | case OBJECT: |
| 80 | return this.object(type); |
| 81 | |
| 82 | case INTERFACE: |
| 83 | return this.interfaces(type); |
| 84 | |
| 85 | case UNION: |
| 86 | return this.union(type); |
| 87 |
nothing calls this directly
no outgoing calls
no test coverage detected