Skip to content

Commit

Permalink
feat: upgraded web ui its much cooler now
Browse files Browse the repository at this point in the history
  • Loading branch information
dosco committed Jan 8, 2023
1 parent bbe42dd commit ea999d4
Show file tree
Hide file tree
Showing 123 changed files with 17,659 additions and 9,881 deletions.
10 changes: 5 additions & 5 deletions core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ func (g *GraphJin) GraphQL(c context.Context,
}

// fast extract name and query type from query
var h graph.FPInfo
if h, err = graph.FastParseBytes(queryBytes); err != nil {
h, err := graph.FastParseBytes(queryBytes)
if err != nil {
return
}
r := gj.newGraphqlReq(rc, h.Operation, h.Name, queryBytes, vars)
Expand All @@ -320,8 +320,8 @@ func (g *GraphJin) GraphQL(c context.Context,
}

// do the query
var resp graphqlResp
if resp, err = gj.query(c1, r); err != nil {
resp, err := gj.query(c1, r)
if err != nil {
return
}
res = resp.res
Expand All @@ -332,7 +332,7 @@ func (g *GraphJin) GraphQL(c context.Context,
}

// if not production then save to allow list
if !gj.prod {
if !gj.prod && r.name != "IntrospectionQuery" {
if err = gj.saveToAllowList(resp.qc, vars, resp.res.ns); err != nil {
return
}
Expand Down
14 changes: 14 additions & 0 deletions core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"unicode"

"github.com/dosco/graphjin/v2/core/internal/allow"
"github.com/dosco/graphjin/v2/core/internal/qcode"
"github.com/dosco/graphjin/v2/core/internal/sdata"
)
Expand Down Expand Up @@ -422,3 +423,16 @@ func isASCII(s string) (int, bool) {
}
return -1, true
}

func (gj *graphjin) initAllowList() (err error) {
gj.allowList, err = allow.New(
gj.log,
gj.fs,
gj.conf.DisableAllowList) // if true then read only

if err != nil {
return fmt.Errorf("failed to initialize allow list: %w", err)
}

return nil
}
5 changes: 5 additions & 0 deletions core/internal/qcode/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func parseTFieldsColumns(tableSchema, tableName string, fields []graph.TField) (
NotNull: f.Required,
PrimaryKey: dir.ID,
UniqueKey: dir.Unique,
FullText: dir.Search,
Blocked: dir.Blocked,
FKeySchema: dir.RelatedSchema,
FKeyTable: dir.RelatedType,
Expand Down Expand Up @@ -162,6 +163,7 @@ func parseTypeDirectives(dir []graph.Directive) (ti typeInfo, err error) {
type tfieldInfo struct {
ID bool
Unique bool
Search bool
Blocked bool
RelatedType string
RelatedField string
Expand All @@ -180,6 +182,9 @@ func parseTFieldDirectives(ft string, dir []graph.Directive) (tfi tfieldInfo, er
case "unique":
tfi.Unique = true

case "search":
tfi.Search = true

case "blocked":
tfi.Blocked = true

Expand Down
100 changes: 73 additions & 27 deletions core/introspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,18 @@ func (gj *graphjin) newGraphQLEngine() (engine *graphql.Engine, err error) {
in.EntryPoints[schema.Mutation] = in.mutation
in.EntryPoints[schema.Subscription] = in.subscription

in.Types["OrderDirection"] = &schema.Enum{Name: "OrderDirection", Values: []*schema.EnumValue{
{
Name: "asc",
Desc: schema.NewDescription("Ascending"),
}, {
Name: "desc",
Desc: schema.NewDescription("Descending"),
in.Types["OrderDirection"] = &schema.Enum{
Name: "OrderDirection",
Values: []*schema.EnumValue{
{
Name: "asc",
Desc: schema.NewDescription("Ascending"),
}, {
Name: "desc",
Desc: schema.NewDescription("Descending"),
},
},
}}
}

in.Types["Cursor"] = &schema.Scalar{
Name: "Cursor",
Expand Down Expand Up @@ -223,17 +226,6 @@ func (in *intro) addTables() error {
return nil
}

// func (in *intro) addToTable(name, desc string, ti sdata.DBTable) {
// k := name + "Output"
// var ot *schema.Object = in.Types[k].(*schema.Object)

// ot.Fields = append(ot.Fields, &schema.Field{
// Name: ti.Name,
// Type: &schema.TypeName{Name: ti.Name + "Output"},
// Desc: schema.NewDescription(desc),
// })
// }

func (in *intro) addTable(name string, ti sdata.DBTable, singular bool) error {
if ti.Blocked {
return nil
Expand Down Expand Up @@ -360,6 +352,42 @@ func (in *intro) addRels(name string, ti sdata.DBTable) error {
}

func (in *intro) addDirectives() {
in.DeclaredDirectives["skip"] = &schema.DirectiveDecl{
Name: "skip",
Desc: schema.NewDescription("Skip field"),
Locs: []string{"FIELD"},
Args: schema.InputValueList{
{
Name: "if",
Desc: schema.NewDescription("Filter expression"),
Type: &schema.TypeName{Name: "String"},
},
{
Name: "ifRole",
Desc: schema.NewDescription("Role name"),
Type: &schema.TypeName{Name: "String"},
},
},
}

in.DeclaredDirectives["include"] = &schema.DirectiveDecl{
Name: "include",
Desc: schema.NewDescription("Include field"),
Locs: []string{"FIELD"},
Args: schema.InputValueList{
{
Name: "if",
Desc: schema.NewDescription("Filter expression"),
Type: &schema.TypeName{Name: "String"},
},
{
Name: "ifRole",
Desc: schema.NewDescription("Role name"),
Type: &schema.TypeName{Name: "String"},
},
},
}

in.DeclaredDirectives["object"] = &schema.DirectiveDecl{
Name: "object",
Desc: schema.NewDescription("Directs the executor to change the return type from a list to a object. All but the first entry of the list will be truncated"),
Expand All @@ -379,14 +407,14 @@ func (in *intro) addDirectives() {
},
}

in.DeclaredDirectives["script"] = &schema.DirectiveDecl{
Name: "script",
Desc: schema.NewDescription("Script the executor to use run specified script against this GraphQL request"),
Locs: []string{"QUERY", "MUTATION", "SUBSCRIPTION"},
in.DeclaredDirectives["schema"] = &schema.DirectiveDecl{
Name: "schema",
Desc: schema.NewDescription("Set the database schema to use for this selector"),
Locs: []string{"FIELD"},
Args: schema.InputValueList{
{
Name: "name",
Desc: schema.NewDescription("Script name"),
Desc: schema.NewDescription("Schema name"),
Type: &schema.TypeName{Name: "String"},
},
},
Expand Down Expand Up @@ -415,14 +443,32 @@ func (in *intro) addDirectives() {
},
},
}
in.DeclaredDirectives["script"] = &schema.DirectiveDecl{
Name: "script",
Desc: schema.NewDescription("Script to run against the query"),
Locs: []string{"QUERY", "MUTATION", "SUBSCRIPTION"},
Args: schema.InputValueList{
{
Name: "name",
Desc: schema.NewDescription("Script name"),
Type: &schema.TypeName{Name: "String"},
},
},
}

in.DeclaredDirectives["validation"] = &schema.DirectiveDecl{
Name: "validation",
Desc: schema.NewDescription("Checks all variables for validation"),
Desc: schema.NewDescription("Validator script to run against the query"),
Locs: []string{"QUERY", "MUTATION", "SUBSCRIPTION"},
Args: schema.InputValueList{
{
Name: "cue",
Desc: schema.NewDescription("Use Cue [https://cuelang.org/] schema to validate variables"),
Name: "src",
Desc: schema.NewDescription("Validation script source"),
Type: &schema.TypeName{Name: "String"},
},
{
Name: "lang",
Desc: schema.NewDescription("Validation script language"),
Type: &schema.TypeName{Name: "String"},
},
},
Expand Down
13 changes: 3 additions & 10 deletions core/remote_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,26 @@ func (s *gstate) execRemoteJoin(c context.Context) (err error) {
// fetch the field name used within the db response json
// that are used to mark insertion points and the mapping between
// those field names and their select objects
var fids [][]byte
var sfmap map[string]*qcode.Select

fids, sfmap, err = s.parentFieldIds()
fids, sfmap, err := s.parentFieldIds()
if err != nil {
return
}

// fetch the field values of the marked insertion points
// these values contain the id to be used with fetching remote data
from := jsn.Get(s.data, fids)
var to []jsn.Field

if len(from) == 0 {
err = errors.New("something wrong no remote ids found in db response")
return
}

to, err = s.resolveRemotes(c, from, sfmap)
to, err := s.resolveRemotes(c, from, sfmap)
if err != nil {
return
}

var ob bytes.Buffer

err = jsn.Replace(&ob, s.data, from, to)
if err != nil {
if err = jsn.Replace(&ob, s.data, from, to); err != nil {
return
}
s.data = ob.Bytes()
Expand Down
12 changes: 0 additions & 12 deletions core/prepare.go → core/rolestmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"io"
"strings"

"github.com/dosco/graphjin/v2/core/internal/allow"
)

// nolint: errcheck
Expand Down Expand Up @@ -52,13 +50,3 @@ func (gj *graphjin) prepareRoleStmt() error {
gj.roleStmt = w.String()
return nil
}

func (gj *graphjin) initAllowList() (err error) {
readOnly := gj.conf.DisableAllowList
gj.allowList, err = allow.New(gj.log, gj.fs, readOnly)
if err != nil {
return fmt.Errorf("failed to initialize allow list: %w", err)
}

return nil
}
11 changes: 5 additions & 6 deletions core/subs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (g *GraphJin) Subscribe(
rc *ReqConfig) (m *Member, err error) {

// get the name, query vars
var h graph.FPInfo
if h, err = graph.FastParse(query); err != nil {
h, err := graph.FastParse(query)
if err != nil {
return
}

Expand Down Expand Up @@ -123,8 +123,7 @@ func (g *GraphJin) SubscribeByName(

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

var item allow.Item
item, err = gj.allowList.GetByName(name, gj.prod)
item, err := gj.allowList.GetByName(name, gj.prod)
if err != nil {
return
}
Expand Down Expand Up @@ -186,8 +185,8 @@ func (gj *graphjin) subscribe(c context.Context, r graphqlReq) (
return
}

var args args
if args, err = sub.s.argListVars(c, r.vars); err != nil {
args, err := sub.s.argListVars(c, r.vars)
if err != nil {
return nil, err
}

Expand Down
42 changes: 0 additions & 42 deletions examples/webshop/cloudbuild.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions examples/webshop/config/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,6 @@ auth:
# exists: true
# value: localhost:8080

# You can add additional named auths to use with actions
# In this example actions using this auth can only be
# called from the Google Appengine Cron service that
# sets a special header to all it's requests
auths:
- name: from_taskqueue
type: header
header:
name: X-Appengine-Cron
exists: true

# Postgres related environment Variables
# GJ_DATABASE_HOST
# GJ_DATABASE_PORT
Expand Down Expand Up @@ -226,16 +215,6 @@ blocklist:
- encrypted
- token

# Create custom actions with their own api endpoints
# For example the below action will be available at /api/v1/actions/refresh_leaderboard_users
# A request to this url will execute the configured SQL query
# which in this case refreshes a materialized view in the database.
# The auth_name is from one of the configured auths
actions:
- name: refresh_leaderboard_users
sql: REFRESH MATERIALIZED VIEW CONCURRENTLY "leaderboard_users"
auth_name: from_taskqueue

resolvers:
- name: payments
type: remote_api
Expand Down
Loading

1 comment on commit ea999d4

@vercel
Copy link

@vercel vercel bot commented on ea999d4 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.