Skip to content

Commit

Permalink
fix: remove flect package
Browse files Browse the repository at this point in the history
  • Loading branch information
dosco committed Jan 1, 2023
1 parent 8802f31 commit 6f882e5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 78 deletions.
8 changes: 0 additions & 8 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ type Config struct {
// and 'anon' when it's not. Use the 'Roles Query' config to add more custom roles
Roles []Role

// Inflections is to add additionally singular to plural mappings
// to the engine (eg. sheep: sheep)
Inflections []string `mapstructure:"inflections" json:"inflections" yaml:"inflections" jsonschema:"-"`

// Disable inflections. Inflections are deprecated and will be
// removed in next major version
EnableInflection bool `mapstructure:"enable_inflection" json:"enable_inflection" yaml:"enable_inflection" jsonschema:"-"`

// Database type name Defaults to 'postgres' (options: mysql, postgres)
DBType string `mapstructure:"db_type" json:"db_type" yaml:"db_type" jsonschema:"title=Database Type,enum=postgres,enum=mysql"`

Expand Down
15 changes: 7 additions & 8 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,13 @@ func (gj *graphjin) initCompilers() error {
var err error

qcc := qcode.Config{
TConfig: gj.conf.tmap,
DefaultBlock: gj.conf.DefaultBlock,
DefaultLimit: gj.conf.DefaultLimit,
DisableAgg: gj.conf.DisableAgg,
DisableFuncs: gj.conf.DisableFuncs,
EnableCamelcase: gj.conf.EnableCamelcase,
EnableInflection: gj.conf.EnableInflection,
DBSchema: gj.schema.DBSchema(),
TConfig: gj.conf.tmap,
DefaultBlock: gj.conf.DefaultBlock,
DefaultLimit: gj.conf.DefaultLimit,
DisableAgg: gj.conf.DisableAgg,
DisableFuncs: gj.conf.DisableFuncs,
EnableCamelcase: gj.conf.EnableCamelcase,
DBSchema: gj.schema.DBSchema(),
}

gj.qc, err = qcode.NewCompiler(gj.schema, qcc)
Expand Down
19 changes: 0 additions & 19 deletions core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ import (

"github.com/dosco/graphjin/v2/core/internal/qcode"
"github.com/dosco/graphjin/v2/core/internal/sdata"
"github.com/gobuffalo/flect"
)

func (gj *graphjin) initConfig() error {
c := gj.conf

if gj.conf.EnableInflection {
if err := initInflection(c); err != nil {
return err
}
}

tm := make(map[string]struct{})

for _, t := range c.Tables {
Expand Down Expand Up @@ -89,18 +82,6 @@ func (gj *graphjin) initConfig() error {
return nil
}

func initInflection(c *Config) error {
for _, v := range c.Inflections {
kv := strings.SplitN(v, ":", 2)
if kv[0] == "" || kv[1] == "" {
return fmt.Errorf("inflections: should be an array of singular:plural values: %s", v)
}
flect.AddPlural(kv[0], kv[1])
flect.AddSingular(kv[1], kv[0])
}
return nil
}

func addTableInfo(c *Config, t Table) error {
obm := map[string][][2]string{}

Expand Down
33 changes: 10 additions & 23 deletions core/internal/qcode/config.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package qcode

import (
"github.com/gobuffalo/flect"
)

type Config struct {
Vars map[string]string
TConfig map[string]TConfig
DefaultBlock bool
DefaultLimit int
DisableAgg bool
DisableFuncs bool
EnableCamelcase bool
EnableInflection bool
DBSchema string
defTrv trval
Vars map[string]string
TConfig map[string]TConfig
DefaultBlock bool
DefaultLimit int
DisableAgg bool
DisableFuncs bool
EnableCamelcase bool
DBSchema string
defTrv trval
}

type TConfig struct {
Expand Down Expand Up @@ -162,15 +157,7 @@ func (co *Compiler) AddRole(role, schema, table string, trc TRConfig) error {
if schema == "" {
schema = co.s.DBSchema()
}

if co.c.EnableInflection {
singular := flect.Singularize(table)
plural := flect.Pluralize(table)
co.tr[(role + ":" + schema + ":" + singular)] = trv
co.tr[(role + ":" + schema + ":" + plural)] = trv
} else {
co.tr[(role + ":" + schema + ":" + table)] = trv
}
co.tr[(role + ":" + schema + ":" + table)] = trv

return nil
}
Expand Down
5 changes: 0 additions & 5 deletions core/internal/qcode/qcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/dosco/graphjin/v2/core/internal/sdata"
"github.com/dosco/graphjin/v2/core/internal/util"
plugin "github.com/dosco/graphjin/v2/plugin"
"github.com/gobuffalo/flect"
)

const (
Expand Down Expand Up @@ -793,10 +792,6 @@ func (co *Compiler) setSingular(fieldName string, sel *Select) {
return
}

if co.c.EnableInflection {
sel.Singular = (flect.Singularize(fieldName) == fieldName)
}

if len(sel.Joins) != 0 {
return
}
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ require (
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822
github.com/brianvoe/gofakeit/v6 v6.20.1
github.com/chirino/graphql v0.0.0-20220710191258-f420c1213e22
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad
github.com/fsnotify/fsnotify v1.6.0
github.com/go-chi/chi v1.5.4
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a
github.com/go-pkgz/expirable-cache v1.0.0
github.com/go-resty/resty/v2 v2.7.0
github.com/go-sql-driver/mysql v1.7.0
github.com/gobuffalo/flect v0.3.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/gomodule/redigo v1.8.9
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/gorilla/websocket v1.5.0
github.com/gosimple/slug v1.13.1
github.com/hashicorp/golang-lru v0.5.4
github.com/jackc/pgx/v5 v5.2.0
github.com/jvatic/goja-babel v0.0.0-20221128111320-553aaca4addf
github.com/jvatic/goja-babel v0.0.0-20221230121756-ba607767ec06
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/klauspost/compress v1.15.13
github.com/lestrrat-go/jwx v1.2.25
github.com/orlangure/gnomock v0.24.0
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.8.2
github.com/rs/cors v1.8.3
github.com/rs/xid v1.4.0
github.com/spf13/afero v1.9.3
github.com/spf13/cobra v1.6.1
Expand Down
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822 h1:hjXJeBcAMS1WGENGqDpzvmgS43oECTx8UXq31UBu0Jw=
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/brianvoe/gofakeit/v6 v6.19.0 h1:g+yJ+meWVEsAmR+bV4mNM/eXI0N+0pZ3D+Mi+G5+YQo=
github.com/brianvoe/gofakeit/v6 v6.19.0/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8=
github.com/brianvoe/gofakeit/v6 v6.20.1 h1:8ihJ60OvPnPJ2W6wZR7M+TTeaZ9bml0z6oy4gvyJ/ek=
github.com/brianvoe/gofakeit/v6 v6.20.1/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
Expand Down Expand Up @@ -360,8 +358,8 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86 h1:E2wycakfddWJ26v+ZyEY91Lb/HEZyaiZhbMX+KQcdmc=
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad h1:EikyYzLzjRNW8lz9VAIUcmrwDAU6PsMRnwblYXb6Ysg=
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -460,8 +458,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gobuffalo/flect v0.3.0 h1:erfPWM+K1rFNIQeRPdeEXxo8yFr/PO17lhRnS8FUrtk=
github.com/gobuffalo/flect v0.3.0/go.mod h1:5pf3aGnsvqvCj50AVni7mJJF8ICxGZ8HomberC3pXLE=
github.com/goccy/go-json v0.9.6/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
Expand Down Expand Up @@ -728,8 +724,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jvatic/goja-babel v0.0.0-20221128111320-553aaca4addf h1:iZyLX34u9gNNkUlFCcCeNlzbaCgIZ4kDXt7Ls4m4nXU=
github.com/jvatic/goja-babel v0.0.0-20221128111320-553aaca4addf/go.mod h1:fl5BoJa86dP/06J7WDW5x6EVzx36HGf4A4VAjk3Kx48=
github.com/jvatic/goja-babel v0.0.0-20221230121756-ba607767ec06 h1:L3bi2PZE3tRApNm9Vm5uqwSltG176mzNglWZWoqqKNU=
github.com/jvatic/goja-babel v0.0.0-20221230121756-ba607767ec06/go.mod h1:WGuISASvrgUN5gu7iQW/8ICM+csAiXmt5ftLzItX3jM=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down Expand Up @@ -943,8 +939,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo=
github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphjin",
"version": "2.0.16",
"version": "2.0.17",
"description": "GraphJin - Build APIs in 5 minutes with GraphQL",
"type": "module",
"main": "./wasm/js/graphjin.js",
Expand Down
Binary file modified wasm/graphjin.wasm
Binary file not shown.

1 comment on commit 6f882e5

@vercel
Copy link

@vercel vercel bot commented on 6f882e5 Jan 1, 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.