Skip to content

Commit

Permalink
feat!: add install script to npm package to setup config folder
Browse files Browse the repository at this point in the history
- [BREAKING] removed action endpoints from serve
- [BREAKING] removed js script as a default in core
- added SubscribeByName api
  • Loading branch information
dosco committed Dec 15, 2022
1 parent ebaeb6d commit 660c1be
Show file tree
Hide file tree
Showing 27 changed files with 285 additions and 290 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ $(BINARY):
@CGO_ENABLED=0 go build $(BUILD_FLAGS) -o $(BINARY) main.go

$(WASM):
@rm -rf ./wasm/runtime
@mkdir -p ./wasm/runtime
@cp $(GOROOT)/misc/wasm/wasm_exec.js ./wasm/runtime/
@cp $(GOROOT)/misc/wasm/wasm_exec.js ./wasm/js/
@GOOS=js GOARCH=wasm go build -o ./wasm/graphjin.wasm ./wasm/*.go

clean:
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

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. Works with **NodeJS** and **GO**. Supports several databases, **Postgres**, **MySQL**, **YugabyteDB**, **Cockroach**, etc.


## Secure out of the box

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
Expand Down Expand Up @@ -84,7 +83,6 @@ console.log("Express server started on port %s", server.address().port);

### Quick install


Mac (Homebrew)

```
Expand Down
15 changes: 5 additions & 10 deletions core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ func newGraphJin(conf *Config, db *sql.DB, dbinfo *sdata.DBInfo, options ...Opti

// ordering of these initializer matter, do not re-order!

if err := gj.initScript(); err != nil {
return nil, err
}

if err := gj.initAPQCache(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -529,13 +525,12 @@ type Header struct {

// Operation function return the operation type and name from the query.
// It uses a very fast algorithm to extract the operation without having to parse the query.
func Operation(query string) (Header, error) {
if h, err := graph.FastParse(query); err == nil {
t := OpType(qcode.GetQTypeByName(h.Operation))
return Header{t, h.Name}, nil
} else {
return Header{}, err
func Operation(query string) (h Header, err error) {
if v, err := graph.FastParse(query); err == nil {
h.Type = OpType(qcode.GetQTypeByName(v.Operation))
h.Name = v.Name
}
return
}

func errResult(name string, err error) *Result {
Expand Down
4 changes: 2 additions & 2 deletions core/internal/qcode/qcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (co *Compiler) compileQuery(qc *QCode, op *graph.Operation, role string) er

sel.Children = make([]int32, 0, 5)

if err := co.compileDirectives(qc, sel, field.Directives); err != nil {
if err := co.compileSelectorDirectives(qc, sel, field.Directives); err != nil {
return err
}

Expand Down Expand Up @@ -949,7 +949,7 @@ func (co *Compiler) compileFieldDirectives(f *Field, dirs []graph.Directive) err
return nil
}

func (co *Compiler) compileDirectives(qc *QCode, sel *Select, dirs []graph.Directive) error {
func (co *Compiler) compileSelectorDirectives(qc *QCode, sel *Select, dirs []graph.Directive) error {
var err error

for i := range dirs {
Expand Down
42 changes: 33 additions & 9 deletions core/subs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,53 @@ func (g *GraphJin) Subscribe(
rc *ReqConfig) (*Member, error) {
var err error

gj := g.Load().(*graphjin)

h, err := graph.FastParse(query)
if err != nil {
panic(err)
}
op := qcode.GetQTypeByName(h.Operation)
name := h.Name

if op != qcode.QTSubscription {
gj := g.Load().(*graphjin)
return gj.subscribeWithOpName(c, op, name, query, vars, rc)
}

func (g *GraphJin) SubscribeByName(
c context.Context,
name string,
vars json.RawMessage,
rc *ReqConfig) (*Member, error) {

gj := g.Load().(*graphjin)
item, err := gj.allowList.GetByName(name, gj.prod)
if err != nil {
return nil, err
}
op := qcode.GetQTypeByName(item.Operation)
query := item.Query

return gj.subscribeWithOpName(c, op, name, query, vars, rc)
}

func (gj *graphjin) subscribeWithOpName(
c context.Context,
op qcode.QType,
name string,
query string,
vars json.RawMessage,
rc *ReqConfig) (*Member, error) {

if op != qcode.QTSubscription && op != qcode.QTQuery {
return nil, errors.New("subscription: not a subscription query")
}

if name == "" {
if gj.prod {
return nil, errors.New("subscription: query name is required")
} else {
h := sha256.Sum256([]byte(query))
name = hex.EncodeToString(h[:])
}
h := sha256.Sum256([]byte(query))
name = hex.EncodeToString(h[:])
}

var role string
var err error

if v, ok := c.Value(UserRoleKey).(string); ok {
role = v
Expand Down
7 changes: 0 additions & 7 deletions core/wasm.go

This file was deleted.

12 changes: 0 additions & 12 deletions core/wasm_not.go

This file was deleted.

78 changes: 74 additions & 4 deletions examples/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"dev": "node index.js"
},
"dependencies": {
"graphjin": "file:../..",
"express": "^4.18.2",
"graphjin": "file:../..",
"pg": "^8.8.0"
},
"devDependencies": {
"path": "^0.12.7"
}
}
Loading

0 comments on commit 660c1be

Please sign in to comment.