diff --git a/packages/pylon-builder/src/schema/schema-parser.ts b/packages/pylon-builder/src/schema/schema-parser.ts index 13c666b..ef78166 100644 --- a/packages/pylon-builder/src/schema/schema-parser.ts +++ b/packages/pylon-builder/src/schema/schema-parser.ts @@ -67,7 +67,10 @@ type ReferenceSchemaType = { returnType: ts.Type args: { // value needs to be inputs type - [key: string]: ts.Type + [key: string]: { + type: ts.Type + documentation: string + } } } @@ -142,7 +145,7 @@ export class SchemaParser { .map((union): Union => { return { ...union, - description: this.getJsDocHeaderFromType(union.rawType) + description: this.getTypeDocumentation(union.rawType) } }) @@ -151,7 +154,7 @@ export class SchemaParser { .map((enumType): Enum => { return { ...enumType, - description: this.getJsDocHeaderFromType(enumType.rawType) + description: this.getTypeDocumentation(enumType.rawType) } }) } @@ -209,7 +212,7 @@ export class SchemaParser { args = `(${field.args .map( arg => - `${addDescription(type.description)}${ + `${addDescription(arg.type.description)}${ arg.name }: ${typeDefinitionToGraphQLType(arg.type)}` ) @@ -284,7 +287,7 @@ export class SchemaParser { } else { this.schema[processing].push({ name, - description: this.getJsDocHeaderFromType(type), + description: this.getTypeDocumentation(type), fields: [] }) @@ -305,7 +308,7 @@ export class SchemaParser { name: propertyName, type: { ...fieldDef, - description: this.getJsDocHeaderFromType(fieldType) + description: this.getTypeDocumentation(fieldType) }, args: [] } @@ -314,22 +317,24 @@ export class SchemaParser { for (const [argName, arg] of Object.entries(property.args)) { const argType = arg - const fieldDef = getTypeDefinition(argType, { + const fieldDef = getTypeDefinition(argType.type, { isInputType: true, propertyName: argName }) if ( - this.schema.scalars.includes(this.checker.typeToString(argType)) + this.schema.scalars.includes( + this.checker.typeToString(argType.type) + ) ) { - fieldDef.name = this.checker.typeToString(argType) + fieldDef.name = this.checker.typeToString(argType.type) } field.args.push({ name: argName, type: { ...fieldDef, - description: this.getJsDocHeaderFromType(argType) + description: argType.documentation } }) } @@ -341,7 +346,7 @@ export class SchemaParser { name: propertyName, type: { ...fieldDef, - description: this.getJsDocHeaderFromType(fieldType) + description: this.getTypeDocumentation(fieldType) } } @@ -352,33 +357,33 @@ export class SchemaParser { } } - private getJsDocHeaderFromType = (type: ts.Type) => { + private getSymbolDocumentation(symbol: ts.Symbol) { let header = '' - if (type.symbol) { - const typeDeclaration = type.symbol.declarations?.[0] as unknown as - | { - jsDoc: ts.JSDoc[] - } - | undefined + header += ts.displayPartsToString( + symbol.getDocumentationComment(this.checker) + ) - const comments = typeDeclaration?.jsDoc?.map(doc => doc.comment).join(' ') + const tags = symbol + .getJsDocTags(this.checker) + .map(t => `@${t.name} ${ts.displayPartsToString(t.text)}`) + .join('\n') - if (comments) { - header = comments - } + if (tags) { + header += '\n' + tags + } - const tags = type.symbol.getJsDocTags() - const tagComments = tags - ?.map(tag => `@${tag.name} ${tag.text?.map(t => t.text).join(' ')}`) - .join('\n') + return header + } - if (tagComments) { - header = `${header} ${tagComments}` - } + private getTypeDocumentation = (type: ts.Type) => { + const symbol = type.getSymbol() + + if (symbol) { + return this.getSymbolDocumentation(symbol) } - return header + return '' } /** @@ -577,7 +582,10 @@ export class SchemaParser { // set args to empty object if not set if (schemaType.args) { - schemaType.args[arg.escapedName as string] = argType + schemaType.args[arg.escapedName as string] = { + type: argType, + documentation: this.getSymbolDocumentation(arg) + } recLoop( argType,