graphjin 0.21.8 → 2.0.0
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 +111 -36
- package/package.json +3 -2
- package/wasm/graphjin.js +24 -0
package/README.md
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
# GraphJin
|
|
1
|
+
# GraphJin, Build APIs in 5 minutes not weeks
|
|
2
2
|
|
|
3
|
-
[](https://pkg.go.dev/github.com/dosco/graphjin)
|
|
4
|
-
[](https://goreportcard.com/report/github.com/dosco/graphjin)
|
|
5
3
|
[](https://github.com/dosco/graphjin/blob/master/LICENSE)
|
|
6
|
-
[
|
|
4
|
+
[!](https://hub.docker.com/r/dosco/graphjin/builds)
|
|
7
5
|
[](https://discord.gg/6pSWCTZ)
|
|
6
|
+
[](https://pkg.go.dev/github.com/dosco/graphjin)
|
|
7
|
+
[](https://goreportcard.com/report/github.com/dosco/graphjin)
|
|
8
8
|
|
|
9
9
|
<!-- [](https://deploy.cloud.run)
|
|
10
10
|
-->
|
|
11
11
|
|
|
12
|
-
GraphJin gives you an instant secure and fast GraphQL API without code.
|
|
12
|
+
GraphJin gives you an instant secure and fast GraphQL API without code. Just use a GraphQL query to define your API and GraphJin automagically converts it into a full featured API. Build your backend APIs 100X faster.
|
|
13
|
+
|
|
14
|
+
Works with NodeJS and GO. Supports several databases, Postgres, MySQL, YugabyteDB Cockroach, etc.
|
|
15
|
+
|
|
16
|
+
## Quick install
|
|
17
|
+
|
|
18
|
+
NPM
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
```
|
|
21
|
+
npm install graphjin
|
|
22
|
+
```
|
|
15
23
|
|
|
16
24
|
Mac (Homebrew)
|
|
17
25
|
|
|
@@ -31,13 +39,76 @@ Debian and Redhat ([releases](https://github.com/dosco/graphjin/releases))
|
|
|
31
39
|
Download the .deb or .rpm from the releases page and install with dpkg -i and rpm -i respectively.
|
|
32
40
|
```
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
## Secure out of the box
|
|
43
|
+
|
|
44
|
+
When you use a query in development it's saved to an allow list and only queries from this allow list can be run in production. In production these allowed queries are converted into prepared statments in the database to protect against sql injection, etc. This makes GraphJin very secure and also very fast since no compiling happens in production all queries go directly to the database. GraphJin is built in Go a language designed by Google to be fast and secure.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Use with NodeJS
|
|
49
|
+
|
|
50
|
+
GraphJin allows you to use GraphQL and the full power of GraphJin to access to create instant APIs without writing and maintaining lines and lines of database code. GraphJin NodeJS currently only supports Postgres compatible databases working on adding MySQL support as well. Example app in [/examples/nodejs](https://github.com/dosco/graphjin/tree/master/examples/nodejs)
|
|
35
51
|
|
|
52
|
+
```console
|
|
53
|
+
npm install graphjin
|
|
36
54
|
```
|
|
37
|
-
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import graphjin from "graphjin";
|
|
58
|
+
import express from "express";
|
|
59
|
+
import http from "http";
|
|
60
|
+
import pg from "pg";
|
|
61
|
+
|
|
62
|
+
const { Client } = pg;
|
|
63
|
+
const db = new Client({
|
|
64
|
+
host: "localhost",
|
|
65
|
+
port: 5432,
|
|
66
|
+
user: "postgres",
|
|
67
|
+
password: "postgres",
|
|
68
|
+
database: "appdb-development",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await db.connect();
|
|
72
|
+
|
|
73
|
+
// config can either be a file (eg. `dev.yml`) or an object
|
|
74
|
+
// const config = { production: true, default_limit: 50 };
|
|
75
|
+
|
|
76
|
+
var gj = await graphjin("./config", "dev.yml", db);
|
|
77
|
+
var app = express();
|
|
78
|
+
var server = http.createServer(app);
|
|
79
|
+
|
|
80
|
+
// subscriptions allow you to have a callback function triggerd
|
|
81
|
+
// automatically when data in your database changes
|
|
82
|
+
const res1 = await gj.subscribe(
|
|
83
|
+
"subscription getUpdatedUser { users(id: $userID) { id email } }",
|
|
84
|
+
null,
|
|
85
|
+
{ userID: 2 }
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
res1.data(function (res) {
|
|
89
|
+
console.log(">", res.data());
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// queries allow you to use graphql to query and update your database
|
|
93
|
+
app.get("/", async function (req, resp) {
|
|
94
|
+
const res2 = await gj.query(
|
|
95
|
+
"query getUser { users(id: $id) { id email } }",
|
|
96
|
+
{ id: 1 },
|
|
97
|
+
{ userID: 1 }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
resp.send(res2.data());
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
server.listen(3000);
|
|
104
|
+
console.log("Express server started on port %s", server.address().port);
|
|
38
105
|
```
|
|
39
106
|
|
|
40
|
-
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Use with GO / Standalone service
|
|
110
|
+
|
|
111
|
+
### Quickly create and deploy new apps
|
|
41
112
|
|
|
42
113
|
```bash
|
|
43
114
|
graphjin new <app_name>
|
|
@@ -47,13 +118,7 @@ docker-compose run api db setup
|
|
|
47
118
|
docker-compose up
|
|
48
119
|
```
|
|
49
120
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
When you use a query in development it's auto-saved in an allow list and only queries from this allow list can be run in production. In production these allowed queries are converted into prepared statments in the database to protect against sql injection, etc. This makes GraphJin very secure and also very fast since no compiling happens in production all queries go directly to the database. GraphJin is built in Go a language designed by Google to be secure and memory safe.
|
|
53
|
-
|
|
54
|
-
## Built for production
|
|
55
|
-
|
|
56
|
-
#### Instantly deploy new versions
|
|
121
|
+
### Instantly deploy new versions
|
|
57
122
|
|
|
58
123
|
```bash
|
|
59
124
|
# Deploy a new config
|
|
@@ -63,24 +128,47 @@ graphjin deploy --host=https://your-server.com --secret="your-secret-key"
|
|
|
63
128
|
graphjin deploy rollback --host=https://your-server.com --secret="your-secret-key"
|
|
64
129
|
```
|
|
65
130
|
|
|
66
|
-
|
|
131
|
+
### Secrets Management
|
|
67
132
|
|
|
68
133
|
```bash
|
|
69
134
|
# Secure save secrets like database passwords and JWT secret keys
|
|
70
135
|
graphjin secrets
|
|
71
136
|
```
|
|
72
137
|
|
|
73
|
-
|
|
138
|
+
### Database Management
|
|
74
139
|
|
|
75
140
|
```bash
|
|
76
141
|
# Create, Migrate and Seed your database
|
|
77
142
|
graphjin db
|
|
78
143
|
```
|
|
79
144
|
|
|
80
|
-
|
|
145
|
+
### Use as a library
|
|
81
146
|
|
|
82
147
|
You can use GraphJin as a library within your own code. The [serv](https://pkg.go.dev/github.com/dosco/graphjin/serv) package exposes the entirely GraphJin standlone service as a library while the [core](https://pkg.go.dev/github.com/dosco/graphjin/core) package exposes just the GraphJin compiler. The [Go docs](https://pkg.go.dev/github.com/dosco/graphjin/core#pkg-examples) are filled with examples on how to use GraphJin within your own apps as a sort of alternative to using ORM packages. GraphJin allows you to use GraphQL and the full power of GraphJin to access your data instead of a limiting ORM.
|
|
83
148
|
|
|
149
|
+
### Use the standalone service as a GO library
|
|
150
|
+
|
|
151
|
+
```golang
|
|
152
|
+
import (
|
|
153
|
+
"github.com/dosco/graphjin/serv"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
gj, err := serv.NewGraphJinService(conf, opt...)
|
|
157
|
+
if err != nil {
|
|
158
|
+
return err
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if err := gj.Start(); err != nil {
|
|
162
|
+
return err
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// if err := gj.Attach(chiRouter); err != nil {
|
|
166
|
+
// return err
|
|
167
|
+
// }
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Use just the core GraphQL compiler in your own GO app
|
|
171
|
+
|
|
84
172
|
```console
|
|
85
173
|
go get github.com/dosco/graphjin/core
|
|
86
174
|
```
|
|
@@ -129,22 +217,9 @@ func main() {
|
|
|
129
217
|
}
|
|
130
218
|
```
|
|
131
219
|
|
|
132
|
-
|
|
220
|
+
---
|
|
133
221
|
|
|
134
|
-
|
|
135
|
-
import (
|
|
136
|
-
"github.com/dosco/graphjin/serv"
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
gj, err := serv.NewGraphJinService(conf, opt...)
|
|
140
|
-
if err != nil {
|
|
141
|
-
return err
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if err := gj.Start(); err != nil {
|
|
145
|
-
return err
|
|
146
|
-
}
|
|
147
|
-
```
|
|
222
|
+
## Built in Web-UI to help craft GraphQL queries
|
|
148
223
|
|
|
149
224
|

|
|
150
225
|
|
|
@@ -181,7 +256,7 @@ With GraphJin your web and mobile developers can start building instantly. All t
|
|
|
181
256
|
|
|
182
257
|
## Highlevel
|
|
183
258
|
|
|
184
|
-
- Works with Postgres, MySQL8, YugabyteDB, CockroachDB,
|
|
259
|
+
- Works with Postgres, MySQL8, YugabyteDB, CockroachDB,
|
|
185
260
|
- Also works with Amazon Aurora/RDS and Google Cloud SQL
|
|
186
261
|
- Supports REST, GraphQL and Websocket APIs
|
|
187
262
|
|
|
@@ -241,4 +316,4 @@ The popular [42papers.com](https://42papers.com) site for discovering trending p
|
|
|
241
316
|
|
|
242
317
|
[Apache Public License 2.0](https://opensource.org/licenses/Apache-2.0)
|
|
243
318
|
|
|
244
|
-
Copyright (c)
|
|
319
|
+
Copyright (c) 2022 Vikram Rangnekar
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphjin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "wasm/graphjin.js",
|
|
6
7
|
"directories": {
|
|
7
8
|
"doc": "docs",
|
|
8
9
|
"example": "examples"
|
package/wasm/graphjin.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "./globals.js"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import * as _ from "./runtime/wasm_exec.js";
|
|
4
|
+
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { dirname, join } from 'path';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
const go = new Go();
|
|
12
|
+
const f = fs.readFileSync(join(__dirname,"./graphjin.wasm"));
|
|
13
|
+
const inst = await WebAssembly.instantiate(f, go.importObject);
|
|
14
|
+
go.run(inst.instance);
|
|
15
|
+
|
|
16
|
+
export default async function(configPath, config, db) {
|
|
17
|
+
if (typeof config === 'string') {
|
|
18
|
+
const conf = {value: config, isFile: true}
|
|
19
|
+
return await createGraphJin(configPath, conf, db, fs)
|
|
20
|
+
} else {
|
|
21
|
+
const conf = {value: JSON.stringify(config), isFile: false}
|
|
22
|
+
return await createGraphJin(configPath, conf, db, fs)
|
|
23
|
+
}
|
|
24
|
+
}
|