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 9 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
11 changes: 9 additions & 2 deletions lib/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,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 @@ -64,6 +70,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 @@ -122,9 +129,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
2 changes: 1 addition & 1 deletion runtime/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
)

var version string
var version = "v0.12.7-38-gacb19ff"

func init() {
// The "version" variable is set by the makefile using -ldflags when using "make build" or goreleaser.
Expand Down
50 changes: 40 additions & 10 deletions runtime/graphql/schemagen/schemagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func transformTypes(types metadata.TypeMap, lti langsupport.LanguageTypeInfo, fo
typeDefs[name] = &TypeDefinition{
Name: name,
Fields: fields,
Docs: t.Docs,
}
}
return typeDefs, errors
Expand All @@ -128,12 +129,14 @@ type FieldDefinition struct {
Name string
Arguments []*ArgumentDefinition
ReturnType string
Docs *metadata.Docs
}

type TypeDefinition struct {
Name string
Fields []*NameTypePair
Fields []*metadata.Field
IsMapType bool
Docs *metadata.Docs
}

type NameTypePair struct {
Expand All @@ -145,6 +148,7 @@ type ArgumentDefinition struct {
Name string
Type string
Default *any
Docs *metadata.Docs
}

// TODO: refactor for readability
Expand Down Expand Up @@ -179,6 +183,7 @@ func transformFunctions(functions metadata.FunctionMap, inputTypeDefs, resultTyp
Name: fieldName,
Arguments: args,
ReturnType: returnType,
Docs: fn.Docs,
}

if isMutation(fn.Name) {
Expand Down Expand Up @@ -333,6 +338,11 @@ func writeSchema(buf *bytes.Buffer, queryFields []*FieldDefinition, mutationFiel
// write input types
for _, t := range inputTypeDefs {
buf.WriteByte('\n')
if t.Docs != nil {
buf.WriteString("\"\"\"\n")
buf.WriteString(strings.Join(t.Docs.Lines, "\n"))
buf.WriteString("\n\"\"\"\n")
}
buf.WriteString("input ")
buf.WriteString(t.Name)
buf.WriteString(" {\n")
Expand All @@ -349,10 +359,20 @@ func writeSchema(buf *bytes.Buffer, queryFields []*FieldDefinition, mutationFiel
// write result types
for _, t := range resultTypeDefs {
buf.WriteByte('\n')
if t.Docs != nil {
buf.WriteString("\"\"\"\n")
buf.WriteString(strings.Join(t.Docs.Lines, "\n"))
buf.WriteString("\n\"\"\"\n")
}
buf.WriteString("type ")
buf.WriteString(t.Name)
buf.WriteString(" {\n")
for _, f := range t.Fields {
if f.Docs != nil {
buf.WriteString(" \"\"\"\n ")
buf.WriteString(strings.Join(f.Docs.Lines, "\n "))
buf.WriteString(" \n \"\"\"\n")
}
buf.WriteString(" ")
buf.WriteString(f.Name)
buf.WriteString(": ")
Expand All @@ -364,6 +384,11 @@ func writeSchema(buf *bytes.Buffer, queryFields []*FieldDefinition, mutationFiel
}

func writeField(buf *bytes.Buffer, field *FieldDefinition) {
if field.Docs != nil {
buf.WriteString(" \"\"\"\n ")
buf.WriteString(strings.Join(field.Docs.Lines, "\n "))
buf.WriteString(" \n \"\"\"\n")
}
buf.WriteString(" ")
buf.WriteString(field.Name)
if len(field.Arguments) > 0 {
Expand Down Expand Up @@ -421,7 +446,7 @@ func convertResults(results []*metadata.Result, lti langsupport.LanguageTypeInfo
return convertType(results[0].Type, lti, typeDefs, false, false)
}

fields := make([]*NameTypePair, len(results))
fields := make([]*metadata.Field, len(results))
for i, r := range results {
name := r.Name
if name == "" {
Expand All @@ -433,7 +458,7 @@ func convertResults(results []*metadata.Result, lti langsupport.LanguageTypeInfo
return "", err
}

fields[i] = &NameTypePair{
fields[i] = &metadata.Field{
Name: name,
Type: typ,
}
Expand All @@ -443,7 +468,7 @@ func convertResults(results []*metadata.Result, lti langsupport.LanguageTypeInfo
return t, nil
}

func getTypeForFields(fields []*NameTypePair, typeDefs map[string]*TypeDefinition) string {
func getTypeForFields(fields []*metadata.Field, typeDefs map[string]*TypeDefinition) string {
// see if an existing type already matches
for _, t := range typeDefs {
if len(t.Fields) != len(fields) {
Expand Down Expand Up @@ -475,20 +500,22 @@ func getTypeForFields(fields []*NameTypePair, typeDefs map[string]*TypeDefinitio
return newType(name, fields, typeDefs)
}

func convertFields(fields []*metadata.Field, lti langsupport.LanguageTypeInfo, typeDefs map[string]*TypeDefinition, forInput bool) ([]*NameTypePair, error) {
func convertFields(fields []*metadata.Field, lti langsupport.LanguageTypeInfo, typeDefs map[string]*TypeDefinition, forInput bool) ([]*metadata.Field, error) {
if len(fields) == 0 {
return nil, nil
}

results := make([]*NameTypePair, len(fields))
results := make([]*metadata.Field, len(fields))
for i, f := range fields {
t, err := convertType(f.Type, lti, typeDefs, true, forInput)
if err != nil {
return nil, err
}
results[i] = &NameTypePair{

results[i] = &metadata.Field{
Name: f.Name,
Type: t,
Docs: f.Docs,
}
}
return results, nil
Expand Down Expand Up @@ -633,7 +660,10 @@ func convertType(typ string, lti langsupport.LanguageTypeInfo, typeDefs map[stri
typeName += "Input"
}

newMapType(typeName, []*NameTypePair{{"key", kt}, {"value", vt}}, typeDefs)
newMapType(typeName, []*metadata.Field{
{Name: "key", Type: kt, Docs: nil},
{Name: "value", Type: vt, Docs: nil},
}, typeDefs)

// The map is represented as a list of the pair type.
// The list might be nullable, but the pair type within the list is always non-nullable.
Expand Down Expand Up @@ -675,7 +705,7 @@ func newScalar(name string, typeDefs map[string]*TypeDefinition) string {
return newType(name, nil, typeDefs)
}

func newType(name string, fields []*NameTypePair, typeDefs map[string]*TypeDefinition) string {
func newType(name string, fields []*metadata.Field, typeDefs map[string]*TypeDefinition) string {
if _, ok := typeDefs[name]; !ok {
typeDefs[name] = &TypeDefinition{
Name: name,
Expand All @@ -685,7 +715,7 @@ func newType(name string, fields []*NameTypePair, typeDefs map[string]*TypeDefin
return name
}

func newMapType(name string, fields []*NameTypePair, typeDefs map[string]*TypeDefinition) string {
func newMapType(name string, fields []*metadata.Field, typeDefs map[string]*TypeDefinition) string {
if _, ok := typeDefs[name]; !ok {
typeDefs[name] = &TypeDefinition{
Name: name,
Expand Down
2 changes: 1 addition & 1 deletion sdk/assemblyscript/examples/http/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ export function createGithubIssue(

// The response will contain the issue data, including the URL of the issue on GitHub.
return response.json<Issue>();
}
}
Loading