@@ -21,21 +21,21 @@ Here is an example of fetching a person from a PostgreSQL database using the Mod
2121package main
2222
2323import (
24- " github.com/hypermodeinc/modus/sdk/go/pkg/postgresql"
24+ " github.com/hypermodeinc/modus/sdk/go/pkg/postgresql"
2525)
2626
2727// the name of the PostgreSQL connection, as specified in the modus.json manifest
2828const host = " my-database"
2929
3030type Person struct {
31- Name string ` json:"name"`
32- Age int ` json:"age"`
31+ Name string ` json:"name"`
32+ Age int ` json:"age"`
3333}
3434
3535func GetPerson (name string ) (*Person , error ) {
36- const query = " select * from persons where name = $1"
37- rows , _ , _ := postgresql.Query [Person](host, query, name)
38- return &rows[0 ], nil
36+ const query = " select * from persons where name = $1"
37+ rows , _ , _ := postgresql.Query [Person](host, query, name)
38+ return &rows[0 ], nil
3939}
4040```
4141
@@ -77,47 +77,47 @@ Here is an example of fetching a person from a Dgraph database using the Modus S
7777package main
7878
7979import (
80- " encoding/json"
81- " github.com/hypermodeinc/modus/sdk/go/pkg/dgraph"
80+ " encoding/json"
81+ " github.com/hypermodeinc/modus/sdk/go/pkg/dgraph"
8282)
8383
8484// the name of the Dgraph connection, as specified in the modus.json manifest
8585const hostName = " my-dgraph"
8686
8787// declare structures used to parse the JSON document returned by Dgraph query.
8888type Person struct {
89- Name string ` json:"name,omitempty"`
90- Age int32 ` json:"age,omitempty"`
89+ Name string ` json:"name,omitempty"`
90+ Age int32 ` json:"age,omitempty"`
9191}
9292
9393// Dgraph returns an array of Persons
9494type GetPersonResponse struct {
95- Persons []*Person ` json:"persons"`
95+ Persons []*Person ` json:"persons"`
9696}
9797
9898func GetPerson (name string ) (*Person , error ) {
99- statement := ` query getPerson($name: string!) {
99+ statement := ` query getPerson($name: string!) {
100100 persons(func: eq(name, $name)) {
101101 name
102102 age
103103 }
104104 }
105105 `
106- variables := map [string ]string {
107- " $name" : name,
108- }
106+ variables := map [string ]string {
107+ " $name" : name,
108+ }
109109
110- response , _ := dgraph.Execute (hostName, &dgraph.Request {
111- Query: &dgraph.Query {
112- Query: statement,
113- Variables: variables,
114- },
115- })
110+ response , _ := dgraph.Execute (hostName, &dgraph.Request {
111+ Query: &dgraph.Query {
112+ Query: statement,
113+ Variables: variables,
114+ },
115+ })
116116
117- var data GetPersonResponse
118- json.Unmarshal ([]byte (response.Json ), &data)
117+ var data GetPersonResponse
118+ json.Unmarshal ([]byte (response.Json ), &data)
119119
120- return data.Persons [0 ], nil
120+ return data.Persons [0 ], nil
121121}
122122
123123```
@@ -135,6 +135,7 @@ class Person {
135135 name: string = " "
136136 age: i32 = 0
137137}
138+
138139// Dgraph returns an array of objects
139140@json
140141class GetPersonResponse {
@@ -181,16 +182,12 @@ import (
181182 " github.com/hypermodeinc/modus/sdk/go/pkg/http"
182183)
183184
184-
185- // Declare structures used to parse the JSON document returned by the REST API
185+ // declare structures used to parse the JSON document returned by the REST API
186186type Person struct {
187187 Name string ` json:"name,omitempty"`
188188 Age int32 ` json:"age,omitempty"`
189189}
190190
191-
192- // Exposing getPerson in the generated GraphQL API
193-
194191func GetPerson (name string ) (*Person , error ) {
195192 url := fmt.Sprintf (" https://example.com/api/person?name=%s " , name)
196193 response , _ := http.Fetch (url)
@@ -213,14 +210,12 @@ class Person {
213210 age: i32 = 0
214211}
215212
216- // Exposing getPerson in the generated GraphQL API
217-
218213export function getPerson(name : string ): Person {
219214 const url = ` https://example.com/api/people?name=${name } `
220215
221216 const response = http .fetch (url )
222217
223- // The API returns Person object as JSON
218+ // the API returns Person object as JSON
224219 return response .json <Person >()
225220}
226221```
@@ -245,7 +240,7 @@ import (
245240// the name of the GraphQL connection, as specified in the modus.json manifest
246241const hostName = " my-graphql-api"
247242
248- // Declare structures used to parse the JSON document returned
243+ // declare structures used to parse the JSON document returned
249244type Person struct {
250245 Name string ` json:"name,omitempty"`
251246 Age int32 ` json:"age,omitempty"`
@@ -279,7 +274,7 @@ import { graphql } from "@hypermode/modus-sdk-as"
279274// the name of the GraphQL connection, as specified in the modus.json manifest
280275const hostName: string = " my-graphql-api"
281276
282- // Declare classes used to parse the JSON document returned
277+ // declare classes used to parse the JSON document returned
283278@json
284279class Person {
285280 name: string = " "
0 commit comments