Skip to content

Commit

Permalink
feat: new improved web-ui using graphiql and graphql explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
dosco committed Feb 21, 2021
1 parent d95959f commit e6a964b
Show file tree
Hide file tree
Showing 36 changed files with 1,931 additions and 3,013 deletions.
6 changes: 0 additions & 6 deletions core/internal/sdata/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type DBSchema struct {
schema string // db schema
name string // db name
tables []DBTable // tables
custom []DBTable // custom resolver tables
vt map[string]VirtualTable // for polymorphic relationships
fm map[string]DBFunction // db functions
tindex map[string]nodeInfo // table index
Expand Down Expand Up @@ -191,7 +190,6 @@ func (s *DBSchema) addRemoteRel(t DBTable) error {
return err
}

s.custom = append(s.custom, t)
return s.addToGraph(t, t.PrimaryCol, pt, pc, RelRemote)
}

Expand Down Expand Up @@ -283,10 +281,6 @@ func (s *DBSchema) GetTables() []DBTable {
return s.tables
}

func (s *DBSchema) GetCustomTables() []DBTable {
return s.custom
}

func (ti *DBTable) getColumn(name string) (DBColumn, bool) {
var c DBColumn
if i, ok := ti.colMap[name]; ok {
Expand Down
47 changes: 31 additions & 16 deletions core/internal/sdata/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"database/sql"
"fmt"
"strings"

"golang.org/x/sync/errgroup"
)

type DBInfo struct {
Expand Down Expand Up @@ -48,26 +50,39 @@ func GetDBInfo(

var dbVersion int
var dbSchema, dbName string
var row *sql.Row
var cols []DBColumn
var funcs []DBFunction

switch dbType {
case "mysql":
row = db.QueryRow(mysqlInfo)
default:
row = db.QueryRow(postgresInfo)
}
g := errgroup.Group{}

if err := row.Scan(&dbVersion, &dbSchema, &dbName); err != nil {
return nil, err
}
g.Go(func() error {
var row *sql.Row
switch dbType {
case "mysql":
row = db.QueryRow(mysqlInfo)
default:
row = db.QueryRow(postgresInfo)
}

cols, err := DiscoverColumns(db, dbType, blockList)
if err != nil {
return nil, err
}
if err := row.Scan(&dbVersion, &dbSchema, &dbName); err != nil {
return err
}
return nil
})

funcs, err := DiscoverFunctions(db, blockList)
if err != nil {
g.Go(func() error {
var err error
if cols, err = DiscoverColumns(db, dbType, blockList); err != nil {
return err
}

if funcs, err = DiscoverFunctions(db, blockList); err != nil {
return err
}
return nil
})

if err := g.Wait(); err != nil {
return nil, err
}

Expand Down
24 changes: 14 additions & 10 deletions core/introspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ func (in *intro) addTables() error {
}
}

for _, t := range in.GetCustomTables() {
if err := in.addTable(t.Name, t); err != nil {
return err
}
desc := fmt.Sprintf(
"Table '%s' is a custom resolved table no column information is available",
t.Name,
)
in.addToTable(t.PrimaryCol.FKeyTable, desc, t)
}
// for _, t := range in.GetCustomTables() {
// if err := in.addTable(t.Name, t); err != nil {
// return err
// }
// desc := fmt.Sprintf(
// "Table '%s' is a custom resolved table no column information is available",
// t.Name,
// )
// in.addToTable(t.PrimaryCol.FKeyTable, desc, t)
// }

return nil
}
Expand All @@ -215,6 +215,10 @@ func (in *intro) addTable(name string, ti sdata.DBTable) error {
return nil
}

if len(ti.Columns) == 0 {
return nil
}

// outputType
ot := &schema.Object{
Name: name + "Output", Fields: schema.FieldList{},
Expand Down
4 changes: 2 additions & 2 deletions examples/webshop/config/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ set_user_id: false
# ip_header sets the header that contains the client ip.
# https://en.wikipedia.org/wiki/Token_bucket
rate_limiter:
rate: 2
bucket: 3
rate: 100
bucket: 20
ip_header: X-Forwarded-For

# Enable additional debugging logs
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/perf v0.0.0-20201207232921-bdcc6220ee90
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
golang.org/x/tools v0.1.0
gonum.org/v1/gonum v0.8.2
Expand Down
284 changes: 0 additions & 284 deletions go.sum

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions internal/serv/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ type errorResp struct {
Error string `json:"error"`
}

func apiV1Handler(servConf *ServConfig) http.Handler {
h, err := auth.WithAuth(http.HandlerFunc(apiV1(servConf)), &servConf.conf.Auth)
func apiV1Handler(sc *ServConfig) http.Handler {
h, err := auth.WithAuth(http.HandlerFunc(sc.apiV1()), &sc.conf.Auth)
if err != nil {
servConf.log.Fatalf("Error initializing auth: %s", err)
sc.log.Fatalf("Error initializing auth: %s", err)
}

if len(servConf.conf.AllowedOrigins) != 0 {
if len(sc.conf.AllowedOrigins) != 0 {
c := cors.New(cors.Options{
AllowedOrigins: servConf.conf.AllowedOrigins,
AllowedOrigins: sc.conf.AllowedOrigins,
AllowCredentials: true,
Debug: servConf.conf.DebugCORS,
Debug: sc.conf.DebugCORS,
})
return c.Handler(h)
}

return h
}

func apiV1(servConf *ServConfig) func(http.ResponseWriter, *http.Request) {
func (sc *ServConfig) apiV1() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if websocket.IsWebSocketUpgrade(r) {
apiV1Ws(servConf, w, r)
sc.apiV1Ws(w, r)
return
}

ct := r.Context()
w.Header().Set("Content-Type", "application/json")

//nolint: errcheck
if servConf.conf.AuthFailBlock && !auth.IsAuth(ct) {
if sc.conf.AuthFailBlock && !auth.IsAuth(ct) {
renderErr(w, errUnauthorized)
return
}
Expand All @@ -86,7 +86,7 @@ func apiV1(servConf *ServConfig) func(http.ResponseWriter, *http.Request) {

rc := core.ReqConfig{Vars: make(map[string]interface{})}

for k, v := range servConf.conf.HeaderVars {
for k, v := range sc.conf.HeaderVars {
rc.Vars[k] = func() string {
if v1, ok := r.Header[v]; ok {
return v1[0]
Expand All @@ -98,8 +98,8 @@ func apiV1(servConf *ServConfig) func(http.ResponseWriter, *http.Request) {
res, err := gj.GraphQL(ct, req.Query, req.Vars, &rc)

if err == nil {
if servConf.conf.CacheControl != "" && res.Operation() == core.OpQuery {
w.Header().Set("Cache-Control", servConf.conf.CacheControl)
if sc.conf.CacheControl != "" && res.Operation() == core.OpQuery {
w.Header().Set("Cache-Control", sc.conf.CacheControl)
}

//nolint: errcheck
Expand All @@ -110,7 +110,7 @@ func apiV1(servConf *ServConfig) func(http.ResponseWriter, *http.Request) {
renderErr(w, err)
}

if servConf.conf.telemetryEnabled() {
if sc.conf.telemetryEnabled() {
span := trace.FromContext(ct)

span.AddAttributes(
Expand All @@ -126,28 +126,28 @@ func apiV1(servConf *ServConfig) func(http.ResponseWriter, *http.Request) {
ochttp.SetRoute(ct, apiRoute)
}

if servConf.logLevel >= LogLevelInfo {
reqLog(servConf, res, err)
if sc.logLevel >= LogLevelInfo {
sc.reqLog(res, err)
}
}
}

func reqLog(servConf *ServConfig, res *core.Result, err error) {
func (sc *ServConfig) reqLog(res *core.Result, err error) {
fields := []zapcore.Field{
zap.String("op", res.OperationName()),
zap.String("name", res.QueryName()),
zap.String("role", res.Role()),
}

if servConf.logLevel >= LogLevelDebug {
if sc.logLevel >= LogLevelDebug {
fields = append(fields, zap.String("sql", res.SQL()))
}

if err != nil {
fields = append(fields, zap.Error(err))
servConf.zlog.Error("Query Failed", fields...)
sc.zlog.Error("Query Failed", fields...)
} else {
servConf.zlog.Info("Query", fields...)
sc.zlog.Info("Query", fields...)
}
}

Expand Down
172 changes: 85 additions & 87 deletions internal/serv/rice-box.go

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions internal/serv/web/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"files": {
"main.css": "/static/css/main.d75bd24d.chunk.css",
"main.js": "/static/js/main.688910ac.chunk.js",
"main.js.map": "/static/js/main.688910ac.chunk.js.map",
"main.css": "/static/css/main.45320ab8.chunk.css",
"main.js": "/static/js/main.0d09a938.chunk.js",
"main.js.map": "/static/js/main.0d09a938.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.bfca2edd.js",
"runtime-main.js.map": "/static/js/runtime-main.bfca2edd.js.map",
"static/js/2.0737febf.chunk.js": "/static/js/2.0737febf.chunk.js",
"static/js/2.0737febf.chunk.js.map": "/static/js/2.0737febf.chunk.js.map",
"static/css/2.bf3fdedd.chunk.css": "/static/css/2.bf3fdedd.chunk.css",
"static/js/2.d3b1e703.chunk.js": "/static/js/2.d3b1e703.chunk.js",
"static/js/2.d3b1e703.chunk.js.map": "/static/js/2.d3b1e703.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.f28f35994e2cae4a56b959bdb12b80a7.js": "/precache-manifest.f28f35994e2cae4a56b959bdb12b80a7.js",
"precache-manifest.4d3ec297e7d942c49a1c6097d69c2156.js": "/precache-manifest.4d3ec297e7d942c49a1c6097d69c2156.js",
"service-worker.js": "/service-worker.js",
"static/css/main.d75bd24d.chunk.css.map": "/static/css/main.d75bd24d.chunk.css.map",
"static/js/2.0737febf.chunk.js.LICENSE.txt": "/static/js/2.0737febf.chunk.js.LICENSE.txt",
"static/media/logo.png": "/static/media/logo.57ee3b60.png"
"static/css/2.bf3fdedd.chunk.css.map": "/static/css/2.bf3fdedd.chunk.css.map",
"static/css/main.45320ab8.chunk.css.map": "/static/css/main.45320ab8.chunk.css.map",
"static/js/2.d3b1e703.chunk.js.LICENSE.txt": "/static/js/2.d3b1e703.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.bfca2edd.js",
"static/js/2.0737febf.chunk.js",
"static/css/main.d75bd24d.chunk.css",
"static/js/main.688910ac.chunk.js"
"static/css/2.bf3fdedd.chunk.css",
"static/js/2.d3b1e703.chunk.js",
"static/css/main.45320ab8.chunk.css",
"static/js/main.0d09a938.chunk.js"
]
}
2 changes: 1 addition & 1 deletion internal/serv/web/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700" rel="stylesheet"/><title>GraphJin - GraphQL API for Rails</title><link href="/static/css/main.d75bd24d.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,l,f=r[0],i=r[1],a=r[2],c=0,s=[];c<f.length;c++)l=f[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,f=1;f<t.length;f++){var i=t[f];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={1:0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var f=this.webpackJsonpweb=this.webpackJsonpweb||[],i=f.push.bind(f);f.push=r,f=f.slice();for(var a=0;a<f.length;a++)r(f[a]);var p=i;t()}([])</script><script src="/static/js/2.0737febf.chunk.js"></script><script src="/static/js/main.688910ac.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700" rel="stylesheet"/><title>GraphJin - GraphQL API for Rails</title><link href="/static/css/2.bf3fdedd.chunk.css" rel="stylesheet"><link href="/static/css/main.45320ab8.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,l,f=r[0],i=r[1],a=r[2],c=0,s=[];c<f.length;c++)l=f[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,f=1;f<t.length;f++){var i=t[f];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={1:0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var f=this.webpackJsonpweb=this.webpackJsonpweb||[],i=f.push.bind(f);f.push=r,f=f.slice();for(var a=0;a<f.length;a++)r(f[a]);var p=i;t()}([])</script><script src="/static/js/2.d3b1e703.chunk.js"></script><script src="/static/js/main.0d09a938.chunk.js"></script></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "a0212703a4e59c07949e5c268abf4ba3",
"url": "/index.html"
},
{
"revision": "c67486becc6e2d56a964",
"url": "/static/css/2.bf3fdedd.chunk.css"
},
{
"revision": "acc8e3407652090a48fb",
"url": "/static/css/main.45320ab8.chunk.css"
},
{
"revision": "c67486becc6e2d56a964",
"url": "/static/js/2.d3b1e703.chunk.js"
},
{
"revision": "96d0ece7a4e0825a058acf042ca7527d",
"url": "/static/js/2.d3b1e703.chunk.js.LICENSE.txt"
},
{
"revision": "acc8e3407652090a48fb",
"url": "/static/js/main.0d09a938.chunk.js"
},
{
"revision": "6981919806c089cef906",
"url": "/static/js/runtime-main.bfca2edd.js"
}
]);

This file was deleted.

2 changes: 1 addition & 1 deletion internal/serv/web/build/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"/precache-manifest.f28f35994e2cae4a56b959bdb12b80a7.js"
"/precache-manifest.4d3ec297e7d942c49a1c6097d69c2156.js"
);

self.addEventListener('message', (event) => {
Expand Down
2 changes: 2 additions & 0 deletions internal/serv/web/build/static/css/2.bf3fdedd.chunk.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/serv/web/build/static/css/main.45320ab8.chunk.css

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

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

2 changes: 0 additions & 2 deletions internal/serv/web/build/static/css/main.d75bd24d.chunk.css

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions internal/serv/web/build/static/js/2.0737febf.chunk.js

This file was deleted.

Loading

0 comments on commit e6a964b

Please sign in to comment.