This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Apply in-code documentation to generated GraphQL #519
Merged
JairusSW
merged 26 commits into
main
from
jairus/hyp-2411-extract-doc-comments-from-functions-and-use-in-graphql
Nov 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6da0765
Use transform to retrieve JSDoc
JairusSW cf452e4
display docs in generated schema
JairusSW dedaa19
setup go transform
JairusSW 5f97d33
use proper GraphQL doc comments
JairusSW 14ff9f3
ignore invalid comments and add fields to docs
JairusSW e430910
extract comments from ast
JairusSW 7d4f49f
remove "fmt"
JairusSW cfef4d1
clean up and finish
JairusSW 710969f
revert http example
JairusSW 57d6d8a
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint bdfd62a
lint/fmt
mattjohnsonpint 0af6644
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint d6b85a8
keep graphql type definitions separate from metadata
JairusSW 726966d
clean up
JairusSW 847faa3
format and fix version
JairusSW c9eb054
only include valid docs in preprocess
JairusSW 500c724
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint c1d56ba
Fix struct/field docs extraction
mattjohnsonpint 40aacd4
Fix function doc extraction
mattjohnsonpint 3c9dab7
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint 1041c92
Update schemagen
mattjohnsonpint b4ceee5
remove visitor dependency
JairusSW f54cc35
lint
JairusSW ce29863
Merge branch 'main' into jairus/hyp-2411-extract-doc-comments-from-fu…
mattjohnsonpint 7f77e80
Adjust comments in simple examples
mattjohnsonpint 8861e7a
Update CHANGELOG.md
mattjohnsonpint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,108 +1,36 @@ | ||
| /* | ||
| * This example is part of the Modus project, licensed under the Apache License 2.0. | ||
| * You may modify and use this example in accordance with the license. | ||
| * See the LICENSE file that accompanied this code for further details. | ||
| /** | ||
| * This is some documentation | ||
| */ | ||
| // This is a single line comment | ||
| @json | ||
| export function foo(player: Player): void {} | ||
|
|
||
| import { http } from "@hypermode/modus-sdk-as"; | ||
| import { Quote, Image, Issue } from "./classes"; | ||
|
|
||
| // This function makes a simple HTTP GET request to example.com, | ||
| // and returns the HTML text of the response. | ||
| export function getExampleHtml(): string { | ||
| const response = http.fetch("https://example.com/"); | ||
| return response.text(); | ||
| } | ||
|
|
||
| // This function makes a request to an API that returns data in JSON format, | ||
| // and returns an object representing the data. | ||
| // It also demonstrates how to check the HTTP response status. | ||
| export function getRandomQuote(): Quote { | ||
| const request = new http.Request("https://zenquotes.io/api/random"); | ||
|
|
||
| const response = http.fetch(request); | ||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to fetch quote. Received: ${response.status} ${response.statusText}`, | ||
| ); | ||
| } | ||
|
|
||
| // The API returns an array of quotes, but we only want the first one. | ||
| return response.json<Quote[]>()[0]; | ||
| } | ||
|
|
||
| // This function makes a request to an API that returns an image, and returns the image data. | ||
| export function getRandomImage(width: i32, height: i32): Image { | ||
| const url = `https://picsum.photos/${width}/${height}`; | ||
| const response = http.fetch(url); | ||
| const contentType = response.headers.get("Content-Type")!; | ||
|
|
||
| return { | ||
| contentType, | ||
| data: response.body, | ||
| }; | ||
| /** | ||
| * This is a class that represents a Three Dimensional Vector | ||
| */ | ||
| @json | ||
| class Vec3 { | ||
| x: f32 = 0.0; | ||
| y: f32 = 0.0; | ||
| z: f32 = 0.0; | ||
| } | ||
|
|
||
| /* | ||
| This function demonstrates a more complex HTTP call. | ||
| It makes a POST request to the GitHub API to create an issue. | ||
|
|
||
| See https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue | ||
|
|
||
| To use it, you must add a GitHub personal access token to your secrets. | ||
| Create a fine-grained token at https://github.com/settings/tokens?type=beta with access | ||
| to write issues to the repository you want to use, then add it to the appropriate secret | ||
| store for your environment. (See the modus documentation for details.) | ||
|
|
||
| NOTE: Do not pass the Authorization header in code when creating the request. | ||
| That would be a security risk, as the token could be exposed in the source code repository. | ||
|
|
||
| Instead, configure the headers in the modus.json manifest as follows: | ||
|
|
||
| "hosts": { | ||
| "github": { | ||
| "baseUrl": "https://api.github.com/", | ||
| "headers": { | ||
| "Authorization": "Bearer {{AUTH_TOKEN}}" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| The Modus runtime will retrieve the token from your secrets and add it to the request. | ||
| */ | ||
| export function createGithubIssue( | ||
| owner: string, | ||
| repo: string, | ||
| title: string, | ||
| body: string, | ||
| ): Issue { | ||
| // The URL for creating an issue in a GitHub repository. | ||
| const url = `https://api.github.com/repos/${owner}/${repo}/issues`; | ||
|
|
||
| // Create a new request with the URL, method, and headers. | ||
| const request = new http.Request(url, { | ||
| method: "POST", | ||
| headers: http.Headers.from([ | ||
| // Do not pass an Authorization header here. See note above. | ||
| ["Accept", "application/vnd.github+json"], | ||
| ["X-GitHub-Api-Version", "2022-11-28"], | ||
| ["Content-Type", "application/json"], | ||
| ]), | ||
|
|
||
| // The request body will be sent as JSON from the Issue object passed here. | ||
| body: http.Content.from(<Issue>{ title, body }), | ||
| } as http.RequestOptions); | ||
|
|
||
| // Send the request and check the response status. | ||
| // NOTE: If you are using a private repository, and you get a 404 error, that could | ||
| // be an authentication issue. Make sure you have created a token as described above. | ||
| const response = http.fetch(request); | ||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to create issue. Received: ${response.status} ${response.statusText}`, | ||
| ); | ||
| } | ||
|
|
||
| // The response will contain the issue data, including the URL of the issue on GitHub. | ||
| return response.json<Issue>(); | ||
| } | ||
| /** | ||
| * This class represents a player in a fictitious game | ||
| */ | ||
| @json | ||
| class Player { | ||
| @alias("first name") | ||
| firstName!: string; | ||
| lastName!: string; | ||
| /** | ||
| * This is some docs describing lastActive | ||
| */ | ||
| lastActive!: i32[]; | ||
| // This is some single line docs describing age | ||
| @omitif("this.age < 18") | ||
| age!: i32; | ||
| @omitnull() | ||
| pos!: Vec3 | null; | ||
| isVerified!: boolean; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.