graphjin 3.0.20 → 3.0.23

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 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
- "context"
147
- "database/sql"
148
- "fmt"
149
- "log"
150
-
151
- "github.com/dosco/graphjin/core/v3"
152
- _ "github.com/jackc/pgx/v4/stdlib"
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
- db, err := sql.Open("pgx", "postgres://postgres:@localhost:5432/example_db")
157
- if err != nil {
158
- log.Fatal(err)
159
- }
160
-
161
- gj, err := core.NewGraphJin(nil, db)
162
- if err != nil {
163
- log.Fatal(err)
164
- }
165
-
166
- query := `
167
- query {
168
- posts {
169
- id
170
- title
171
- }
172
- }`
173
-
174
- ctx := context.Background()
175
- ctx = context.WithValue(ctx, core.UserIDKey, 1)
176
-
177
- res, err := gj.GraphQL(ctx, query, nil, nil)
178
- if err != nil {
179
- log.Fatal(err)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphjin",
3
- "version": "3.0.20",
3
+ "version": "3.0.23",
4
4
  "description": "GraphJin - Build APIs in 5 minutes with GraphQL",
5
5
  "type": "module",
6
6
  "main": "./wasm/js/graphjin.js",
Binary file