Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6da0765
Use transform to retrieve JSDoc
JairusSW Oct 28, 2024
cf452e4
display docs in generated schema
JairusSW Oct 31, 2024
dedaa19
setup go transform
JairusSW Nov 1, 2024
5f97d33
use proper GraphQL doc comments
JairusSW Nov 4, 2024
14ff9f3
ignore invalid comments and add fields to docs
JairusSW Nov 7, 2024
e430910
extract comments from ast
JairusSW Nov 11, 2024
7d4f49f
remove "fmt"
JairusSW Nov 11, 2024
cfef4d1
clean up and finish
JairusSW Nov 11, 2024
710969f
revert http example
JairusSW Nov 11, 2024
57d6d8a
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint Nov 12, 2024
bdfd62a
lint/fmt
mattjohnsonpint Nov 12, 2024
0af6644
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint Nov 13, 2024
d6b85a8
keep graphql type definitions separate from metadata
JairusSW Nov 14, 2024
726966d
clean up
JairusSW Nov 14, 2024
847faa3
format and fix version
JairusSW Nov 16, 2024
c9eb054
only include valid docs in preprocess
JairusSW Nov 21, 2024
500c724
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint Nov 21, 2024
c1d56ba
Fix struct/field docs extraction
mattjohnsonpint Nov 22, 2024
40aacd4
Fix function doc extraction
mattjohnsonpint Nov 22, 2024
3c9dab7
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint Nov 22, 2024
1041c92
Update schemagen
mattjohnsonpint Nov 22, 2024
b4ceee5
remove visitor dependency
JairusSW Nov 22, 2024
f54cc35
lint
JairusSW Nov 22, 2024
ce29863
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint Nov 23, 2024
7f77e80
Adjust comments in simple examples
mattjohnsonpint Nov 23, 2024
8861e7a
Update CHANGELOG.md
mattjohnsonpint Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## UNRELEASED - Runtime

- feat: Apply in-code documentation to generated GraphQL [#519](https://github.com/hypermodeinc/modus/pull/519)
- feat: Reduce logger output during development [#576](https://github.com/hypermodeinc/modus/pull/576)
- chore: Trigger internal release pipeline at the end of the release-runtime workflow [#577](https://github.com/hypermodeinc/modus/pull/577)
- feat: Add API explorer to runtime [#578](https://github.com/hypermodeinc/modus/pull/578)
Expand Down
11 changes: 9 additions & 2 deletions lib/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ type Metadata struct {
Types TypeMap `json:"types,omitempty"`
}

type Docs struct {
Lines []string `json:"lines"`
}

type Function struct {
Name string `json:"-"`
Parameters []*Parameter `json:"parameters,omitempty"`
Results []*Result `json:"results,omitempty"`
Docs *Docs `json:"docs,omitempty"`
}

type TypeDefinition struct {
Name string `json:"-"`
Id uint32 `json:"id,omitempty"`
Fields []*Field `json:"fields,omitempty"`
Docs *Docs `json:"docs,omitempty"`
}

type Parameter struct {
Expand All @@ -60,6 +66,7 @@ type Result struct {
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
Docs *Docs `json:"docs,omitempty"`
}

func (p *Parameter) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -118,9 +125,9 @@ func (m *Metadata) SdkVersion() string {
func (m *Metadata) GetTypeDefinition(typ string) (*TypeDefinition, error) {
switch typ {
case "[]byte":
return &TypeDefinition{typ, 1, nil}, nil
return &TypeDefinition{typ, 1, nil, nil}, nil
case "string":
return &TypeDefinition{typ, 2, nil}, nil
return &TypeDefinition{typ, 2, nil, nil}, nil
}

def, ok := m.Types[typ]
Expand Down
77 changes: 74 additions & 3 deletions runtime/graphql/schemagen/schemagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ func transformTypes(types metadata.TypeMap, lti langsupport.LanguageTypeInfo, fo
continue
}

typeDefs[name] = &TypeDefinition{
typeDef := &TypeDefinition{
Name: name,
Fields: fields,
}

if t.Docs != nil {
typeDef.DocLines = t.Docs.Lines
}

typeDefs[name] = typeDef
}
return typeDefs, errors
}
Expand All @@ -131,12 +137,14 @@ type FieldDefinition struct {
Type string
Arguments []*ArgumentDefinition
Function string
DocLines []string
}

type TypeDefinition struct {
Name string
Fields []*FieldDefinition
IsMapType bool
DocLines []string
}

type ArgumentDefinition struct {
Expand Down Expand Up @@ -186,6 +194,10 @@ func transformFunctions(functions metadata.FunctionMap, inputTypeDefs, resultTyp
Function: fn.Name,
}

if fn.Docs != nil {
field.DocLines = fn.Docs.Lines
}

if filter(field) {
if isMutation(fn.Name) {
mutationFields = append(mutationFields, field)
Expand Down Expand Up @@ -329,14 +341,34 @@ func writeSchema(buf *bytes.Buffer, root *RootObjects, scalarTypes []string, inp
buf.WriteByte('\n')
}
}

// write input types
for _, t := range inputTypeDefs {
buf.WriteByte('\n')

if len(t.DocLines) > 0 {
buf.WriteString("\"\"\"\n")
for _, line := range t.DocLines {
buf.WriteString(line)
buf.WriteByte('\n')
}
buf.WriteString("\"\"\"\n")
}

buf.WriteString("input ")
buf.WriteString(t.Name)
buf.WriteString(" {\n")
for _, f := range t.Fields {

if len(f.DocLines) > 0 {
buf.WriteString(" \"\"\"\n")
for _, line := range f.DocLines {
buf.WriteString(" ")
buf.WriteString(line)
buf.WriteByte('\n')
}
buf.WriteString(" \"\"\"\n")
}

buf.WriteString(" ")
buf.WriteString(f.Name)
buf.WriteString(": ")
Expand All @@ -349,10 +381,31 @@ func writeSchema(buf *bytes.Buffer, root *RootObjects, scalarTypes []string, inp
// write result types
for _, t := range resultTypeDefs {
buf.WriteByte('\n')

if len(t.DocLines) > 0 {
buf.WriteString("\"\"\"\n")
for _, line := range t.DocLines {
buf.WriteString(line)
buf.WriteByte('\n')
}
buf.WriteString("\"\"\"\n")
}

buf.WriteString("type ")
buf.WriteString(t.Name)
buf.WriteString(" {\n")
for _, f := range t.Fields {

if len(f.DocLines) > 0 {
buf.WriteString(" \"\"\"\n")
for _, line := range f.DocLines {
buf.WriteString(" ")
buf.WriteString(line)
buf.WriteByte('\n')
}
buf.WriteString(" \"\"\"\n")
}

buf.WriteString(" ")
buf.WriteString(f.Name)
buf.WriteString(": ")
Expand All @@ -364,6 +417,17 @@ func writeSchema(buf *bytes.Buffer, root *RootObjects, scalarTypes []string, inp
}

func writeField(buf *bytes.Buffer, field *FieldDefinition) {

if len(field.DocLines) > 0 {
buf.WriteString(" \"\"\"\n")
for _, line := range field.DocLines {
buf.WriteString(" ")
buf.WriteString(line)
buf.WriteByte('\n')
}
buf.WriteString(" \"\"\"\n")
}

buf.WriteString(" ")
buf.WriteString(field.Name)
if len(field.Arguments) > 0 {
Expand Down Expand Up @@ -486,10 +550,17 @@ func convertFields(fields []*metadata.Field, lti langsupport.LanguageTypeInfo, t
if err != nil {
return nil, err
}
results[i] = &FieldDefinition{

fieldDef := &FieldDefinition{
Name: f.Name,
Type: t,
}

if f.Docs != nil {
fieldDef.DocLines = f.Docs.Lines
}

results[i] = fieldDef
}
return results, nil
}
Expand Down
20 changes: 15 additions & 5 deletions sdk/assemblyscript/examples/simple/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

import { Person } from "./person";

// This function adds two 32-bit signed integers together, and returns the result.
/**
* Adds two integers together, and returns the result.
*/
export function add(a: i32, b: i32): i32 {
return a + b;
}

// This function takes a first name and a last name, and concatenates them to returns a full name.
/**
* Combines the first and last name of a person, and returns the full name.
*/
export function getFullName(firstName: string, lastName: string): string {
return `${firstName} ${lastName}`;
}

// This function makes a list of people, and returns it.
/**
* Gets a list of people.
*/
export function getPeople(): Person[] {
return [
new Person("Bob", "Smith"),
Expand All @@ -25,15 +31,19 @@ export function getPeople(): Person[] {
];
}

// This function returns a random person from the list of people.
/**
* Gets a random person from the list of people.
*/
export function getRandomPerson(): Person {
const people = getPeople();
const index = <i32>Math.floor(Math.random() * people.length);
const person = people[index];
return person;
}

// This function demonstrates various ways to log messages and errors.
/**
* Demonstrates logging error messages at different levels.
*/
export function testErrors(): void {
// This is a simple log message. It has no level.
console.log("This is a simple log message.");
Expand Down
15 changes: 15 additions & 0 deletions sdk/assemblyscript/examples/simple/assembly/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@
// This class is used in the examples.
// It is separated just to demonstrated how to use multiple files.
// Note, this is just one way to define a class in AssemblyScript.

/**
* A simple object representing a person.
*/
export class Person {
/**
* The first name of the person.
*/
firstName: string;

/**
* The last name of the person.
*/
lastName: string;

/**
* The full name of the person.
*/
fullName: string;

constructor(firstName: string, lastName: string) {
Expand Down
Loading
Loading