graphjin 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -33
- package/package.json +1 -1
- package/wasm/graphjin.wasm +0 -0
package/README.md
CHANGED
|
@@ -57,6 +57,19 @@ query getProducts {
|
|
|
57
57
|
}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
**Note**: The corresponding SQL for creating the table (POSTGRES)
|
|
61
|
+
|
|
62
|
+
```sql
|
|
63
|
+
CREATE TABLE products (
|
|
64
|
+
id SERIAL NOT NULL,
|
|
65
|
+
name TEXT NOT NULL,
|
|
66
|
+
price INTEGER NOT NULL,
|
|
67
|
+
owner_id INTEGER NOT NULL,
|
|
68
|
+
category_id INTEGER NOT NULL,
|
|
69
|
+
PRIMARY KEY(id)
|
|
70
|
+
);
|
|
71
|
+
```
|
|
72
|
+
|
|
60
73
|
## Secure out of the box
|
|
61
74
|
|
|
62
75
|
In production all queries are always read from locally saved copies not from what the client sends hence clients cannot modify the query. This makes
|
|
@@ -143,44 +156,52 @@ go get github.com/dosco/graphjin/core/v3
|
|
|
143
156
|
package main
|
|
144
157
|
|
|
145
158
|
import (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
"context"
|
|
160
|
+
"database/sql"
|
|
161
|
+
"log"
|
|
162
|
+
"net/http"
|
|
163
|
+
|
|
164
|
+
"github.com/dosco/graphjin/core"
|
|
165
|
+
"github.com/go-chi/chi/v5"
|
|
166
|
+
_ "github.com/jackc/pgx/v5/stdlib"
|
|
153
167
|
)
|
|
154
168
|
|
|
155
169
|
func main() {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
query {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
db, err := sql.Open("pgx", "postgres://postgres:@localhost:5432/exampledb?sslmode=disable")
|
|
171
|
+
if err != nil {
|
|
172
|
+
log.Fatal(err)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
gj, err := core.NewGraphJin(nil, db)
|
|
176
|
+
if err != nil {
|
|
177
|
+
log.Fatal(err)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
query := `
|
|
181
|
+
query getPosts {
|
|
182
|
+
posts {
|
|
183
|
+
id
|
|
184
|
+
title
|
|
185
|
+
}
|
|
186
|
+
posts_cursor
|
|
187
|
+
}`
|
|
188
|
+
|
|
189
|
+
router := chi.NewRouter()
|
|
190
|
+
router.Get("/", func(w http.ResponseWriter, request *http.Request) {
|
|
191
|
+
context := context.WithValue(request.Context(), core.UserIDKey, 1)
|
|
192
|
+
res, err := gj.GraphQL(context, query, nil, nil)
|
|
193
|
+
if err != nil {
|
|
194
|
+
log.Fatal(err)
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
w.Write(res.Data)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
log.Println("Go server started on port 3000")
|
|
201
|
+
http.ListenAndServe(":3000", router)
|
|
181
202
|
|
|
182
|
-
fmt.Println(string(res.Data))
|
|
183
203
|
}
|
|
204
|
+
|
|
184
205
|
```
|
|
185
206
|
|
|
186
207
|
### Use GraphJin Service
|
package/package.json
CHANGED
package/wasm/graphjin.wasm
CHANGED
|
Binary file
|