Add HTTP GZip compression

This commit is contained in:
Vikram Rangnekar 2019-12-31 01:30:20 -05:00
parent 343589c3bd
commit a40bd7fca5
16 changed files with 204 additions and 194 deletions

View File

@ -12,7 +12,8 @@
## What is Super Graph ## What is Super Graph
Super Graph is a micro-service that instantly and without code gives you a high performance and secure GraphQL API. Your GraphQL queries are auto translated into a single fast SQL query. No more writing API code as you develop your web frontend just make the query you need and Super Graph will do the rest. Is designed to 100x your developer productivity. Super Graph will instantly and without you writing code provide you a high performance and secure GraphQL API for Postgres DB. GraphQL queries are translated into a single fast SQL query. No more writing API code as you develop
your web frontend just make the query you need and Super Graph will do the rest.
Super Graph has a rich feature set like integrating with your existing Ruby on Rails apps, joining your DB with data from remote APIs, role and attribute based access control, support for JWT tokens, built-in DB mutations and seeding, and a lot more. Super Graph has a rich feature set like integrating with your existing Ruby on Rails apps, joining your DB with data from remote APIs, role and attribute based access control, support for JWT tokens, built-in DB mutations and seeding, and a lot more.
@ -33,15 +34,14 @@ This compiler is what sits at the heart of Super Graph with layers of useful fun
## Features ## Features
- Complex nested queries and mutations
- Auto learns database tables and relationships
- Role and Attribute based access control - Role and Attribute based access control
- Works with existing Ruby-On-Rails apps
- Automatically learns database schemas and relationships
- Full text search and aggregations - Full text search and aggregations
- Rails authentication supported (Redis, Memcache, Cookie)
- JWT tokens supported (Auth0, etc) - JWT tokens supported (Auth0, etc)
- Join database with remote REST APIs - Join database queries with remote REST APIs
- Highly optimized and fast Postgres SQL queries - Also works with existing Ruby-On-Rails apps
- GraphQL queries and mutations - Rails authentication supported (Redis, Memcache, Cookie)
- A simple config file - A simple config file
- High performance GO codebase - High performance GO codebase
- Tiny docker image and low memory requirements - Tiny docker image and low memory requirements

View File

@ -5,6 +5,9 @@ web_ui: true
# debug, info, warn, error, fatal, panic # debug, info, warn, error, fatal, panic
log_level: "debug" log_level: "debug"
# enable or disable http compression (uses gzip)
http_compress: true
# When production mode is 'true' only queries # When production mode is 'true' only queries
# from the allow list are permitted. # from the allow list are permitted.
# When it's 'false' all queries are saved to the # When it's 'false' all queries are saved to the
@ -97,6 +100,7 @@ database:
# Enable this if you need the user id in triggers, etc # Enable this if you need the user id in triggers, etc
set_user_id: false set_user_id: false
# database ping timeout is used for db health checking
ping_timeout: 1m ping_timeout: 1m
# Define additional variables here to be used with filters # Define additional variables here to be used with filters

View File

@ -9,6 +9,9 @@ web_ui: false
# debug, info, warn, error, fatal, panic, disable # debug, info, warn, error, fatal, panic, disable
log_level: "info" log_level: "info"
# enable or disable http compression (uses gzip)
http_compress: true
# When production mode is 'true' only queries # When production mode is 'true' only queries
# from the allow list are permitted. # from the allow list are permitted.
# When it's 'false' all queries are saved to the # When it's 'false' all queries are saved to the
@ -56,4 +59,5 @@ database:
# Enable this if you need the user id in triggers, etc # Enable this if you need the user id in triggers, etc
set_user_id: false set_user_id: false
ping_timeout: 5m # database ping timeout is used for db health checking
ping_timeout: 5m

View File

@ -1339,6 +1339,9 @@ web_ui: true
# debug, info, warn, error, fatal, panic # debug, info, warn, error, fatal, panic
log_level: "debug" log_level: "debug"
# enable or disable http compression (uses gzip)
http_compress: true
# When production mode is 'true' only queries # When production mode is 'true' only queries
# from the allow list are permitted. # from the allow list are permitted.
# When it's 'false' all queries are saved to the # When it's 'false' all queries are saved to the

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/dosco/super-graph
require ( require (
github.com/GeertJohan/go.rice v1.0.0 github.com/GeertJohan/go.rice v1.0.0
github.com/Masterminds/semver v1.5.0 github.com/Masterminds/semver v1.5.0
github.com/NYTimes/gziphandler v1.1.1
github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3 github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
github.com/brianvoe/gofakeit v3.18.0+incompatible github.com/brianvoe/gofakeit v3.18.0+incompatible

2
go.sum
View File

@ -7,6 +7,8 @@ github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voi
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3 h1:+qz9Ga6l6lKw6fgvk5RMV5HQznSLvI8Zxajwdj4FhFg= github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3 h1:+qz9Ga6l6lKw6fgvk5RMV5HQznSLvI8Zxajwdj4FhFg=
github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3/go.mod h1:FlkD11RtgMTYjVuBnb7cxoHmQGqvPpCsr2atC88nl/M= github.com/adjust/gorails v0.0.0-20171013043634-2786ed0c03d3/go.mod h1:FlkD11RtgMTYjVuBnb7cxoHmQGqvPpCsr2atC88nl/M=

View File

@ -6,13 +6,15 @@ import (
"strings" "strings"
) )
var ( type ctxkey int
userIDProviderKey = "user_id_provider"
userIDKey = "user_id" const (
userRoleKey = "user_role" userIDProviderKey ctxkey = iota
userIDKey
userRoleKey
) )
func headerAuth(next http.HandlerFunc) http.HandlerFunc { func headerAuth(next http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
@ -35,7 +37,7 @@ func headerAuth(next http.HandlerFunc) http.HandlerFunc {
} }
} }
func withAuth(next http.HandlerFunc) http.HandlerFunc { func withAuth(next http.Handler) http.Handler {
at := conf.Auth.Type at := conf.Auth.Type
ru := conf.Auth.Rails.URL ru := conf.Auth.Rails.URL

View File

@ -14,7 +14,7 @@ const (
jwtAuth0 int = iota + 1 jwtAuth0 int = iota + 1
) )
func jwtHandler(next http.HandlerFunc) http.HandlerFunc { func jwtHandler(next http.Handler) http.HandlerFunc {
var key interface{} var key interface{}
var jwtProvider int var jwtProvider int

View File

@ -12,7 +12,7 @@ import (
"github.com/garyburd/redigo/redis" "github.com/garyburd/redigo/redis"
) )
func railsRedisHandler(next http.HandlerFunc) http.HandlerFunc { func railsRedisHandler(next http.Handler) http.HandlerFunc {
cookie := conf.Auth.Cookie cookie := conf.Auth.Cookie
if len(cookie) == 0 { if len(cookie) == 0 {
errlog.Fatal().Msg("no auth.cookie defined") errlog.Fatal().Msg("no auth.cookie defined")
@ -66,7 +66,7 @@ func railsRedisHandler(next http.HandlerFunc) http.HandlerFunc {
} }
} }
func railsMemcacheHandler(next http.HandlerFunc) http.HandlerFunc { func railsMemcacheHandler(next http.Handler) http.HandlerFunc {
cookie := conf.Auth.Cookie cookie := conf.Auth.Cookie
if len(cookie) == 0 { if len(cookie) == 0 {
errlog.Fatal().Msg("no auth.cookie defined") errlog.Fatal().Msg("no auth.cookie defined")
@ -108,7 +108,7 @@ func railsMemcacheHandler(next http.HandlerFunc) http.HandlerFunc {
} }
} }
func railsCookieHandler(next http.HandlerFunc) http.HandlerFunc { func railsCookieHandler(next http.Handler) http.HandlerFunc {
cookie := conf.Auth.Cookie cookie := conf.Auth.Cookie
if len(cookie) == 0 { if len(cookie) == 0 {
errlog.Fatal().Msg("no auth.cookie defined") errlog.Fatal().Msg("no auth.cookie defined")

View File

@ -20,6 +20,7 @@ type config struct {
HostPort string `mapstructure:"host_port"` HostPort string `mapstructure:"host_port"`
Host string Host string
Port string Port string
HTTPGZip bool `mapstructure:"http_compress"`
WebUI bool `mapstructure:"web_ui"` WebUI bool `mapstructure:"web_ui"`
LogLevel string `mapstructure:"log_level"` LogLevel string `mapstructure:"log_level"`
EnableTracing bool `mapstructure:"enable_tracing"` EnableTracing bool `mapstructure:"enable_tracing"`

View File

@ -61,7 +61,7 @@ type resolver struct {
Duration time.Duration `json:"duration"` Duration time.Duration `json:"duration"`
} }
func apiv1Http(w http.ResponseWriter, r *http.Request) { func apiV1(w http.ResponseWriter, r *http.Request) {
ctx := &coreContext{Context: r.Context()} ctx := &coreContext{Context: r.Context()}
//nolint: errcheck //nolint: errcheck

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,7 @@ import (
"time" "time"
rice "github.com/GeertJohan/go.rice" rice "github.com/GeertJohan/go.rice"
"github.com/NYTimes/gziphandler"
"github.com/dosco/super-graph/psql" "github.com/dosco/super-graph/psql"
"github.com/dosco/super-graph/qcode" "github.com/dosco/super-graph/qcode"
) )
@ -121,11 +122,18 @@ func startHTTP() {
} }
func routeHandler() http.Handler { func routeHandler() http.Handler {
var apiH http.Handler
if conf.HTTPGZip {
gzipH := gziphandler.MustNewGzipLevelHandler(6)
apiH = gzipH(http.HandlerFunc(apiV1))
} else {
apiH = http.HandlerFunc(apiV1)
}
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/health", health)
mux.Handle("/health", http.HandlerFunc(health)) mux.Handle("/api/v1/graphql", withAuth(apiH))
mux.Handle("/api/v1/graphql", withAuth(apiv1Http))
if conf.WebUI { if conf.WebUI {
mux.Handle("/", http.FileServer(rice.MustFindBox("../web/build").HTTPBox())) mux.Handle("/", http.FileServer(rice.MustFindBox("../web/build").HTTPBox()))

View File

@ -5,6 +5,9 @@ web_ui: true
# debug, info, warn, error, fatal, panic # debug, info, warn, error, fatal, panic
log_level: "info" log_level: "info"
# enable or disable http compression (uses gzip)
http_compress: true
# When production mode is 'true' only queries # When production mode is 'true' only queries
# from the allow list are permitted. # from the allow list are permitted.
# When it's 'false' all queries are saved to the # When it's 'false' all queries are saved to the
@ -97,6 +100,9 @@ database:
# Enable this if you need the user id in triggers, etc # Enable this if you need the user id in triggers, etc
set_user_id: false set_user_id: false
# database ping timeout is used for db health checking
ping_timeout: 1m
# Define additional variables here to be used with filters # Define additional variables here to be used with filters
variables: variables:
admin_account_id: "5" admin_account_id: "5"

View File

@ -8,6 +8,10 @@ web_ui: false
# debug, info, warn, error, fatal, panic, disable # debug, info, warn, error, fatal, panic, disable
log_level: "warn" log_level: "warn"
# enable or disable http compression (uses gzip)
http_compress: true
# When production mode is 'true' only queries # When production mode is 'true' only queries
# from the allow list are permitted. # from the allow list are permitted.
# When it's 'false' all queries are saved to the # When it's 'false' all queries are saved to the
@ -53,4 +57,7 @@ database:
# Set session variable "user.id" to the user id # Set session variable "user.id" to the user id
# Enable this if you need the user id in triggers, etc # Enable this if you need the user id in triggers, etc
set_user_id: false set_user_id: false
# database ping timeout is used for db health checking
ping_timeout: 5m

View File

@ -2816,15 +2816,7 @@ code-point-at@^1.0.0:
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
codemirror-graphql@^0.6.11: codemirror-graphql@^0.6.11, codemirror-graphql@timsuchanek/codemirror-graphql#details-fix:
version "0.6.12"
resolved "https://registry.yarnpkg.com/codemirror-graphql/-/codemirror-graphql-0.6.12.tgz#91a273fe5188857524a30221d06e645b4ca41f00"
integrity sha512-7YP956JubbWkmk9QqKy62CZgdGbEulHNJkz2/aUDTpsE1KrQtRrT9WzStJaxAOEX2k4wUOpojUX2ItPxa69kFA==
dependencies:
graphql-language-service-interface "^1.0.16"
graphql-language-service-parser "^0.1.14"
codemirror-graphql@timsuchanek/codemirror-graphql#details-fix:
version "0.6.12" version "0.6.12"
resolved "https://codeload.github.com/timsuchanek/codemirror-graphql/tar.gz/801ec32683c38d6dc0f8f7bc19014a111edc9ebd" resolved "https://codeload.github.com/timsuchanek/codemirror-graphql/tar.gz/801ec32683c38d6dc0f8f7bc19014a111edc9ebd"
dependencies: dependencies:
@ -4882,7 +4874,7 @@ graphql-import@^0.7.1:
lodash "^4.17.4" lodash "^4.17.4"
resolve-from "^4.0.0" resolve-from "^4.0.0"
graphql-language-service-interface@^1.0.16, graphql-language-service-interface@^1.0.18: graphql-language-service-interface@^1.0.18:
version "1.3.2" version "1.3.2"
resolved "https://registry.yarnpkg.com/graphql-language-service-interface/-/graphql-language-service-interface-1.3.2.tgz#4bd5d49e23766c3d2ab65d110f26f10e321cc000" resolved "https://registry.yarnpkg.com/graphql-language-service-interface/-/graphql-language-service-interface-1.3.2.tgz#4bd5d49e23766c3d2ab65d110f26f10e321cc000"
integrity sha512-sOxFV5sBSnYtKIFHtlmAHHVdhok7CRbvCPLcuHvL4Q1RSgKRsPpeHUDKU+yCbmlonOKn/RWEKaYWrUY0Sgv70A== integrity sha512-sOxFV5sBSnYtKIFHtlmAHHVdhok7CRbvCPLcuHvL4Q1RSgKRsPpeHUDKU+yCbmlonOKn/RWEKaYWrUY0Sgv70A==
@ -4892,13 +4884,6 @@ graphql-language-service-interface@^1.0.16, graphql-language-service-interface@^
graphql-language-service-types "^1.2.2" graphql-language-service-types "^1.2.2"
graphql-language-service-utils "^1.2.2" graphql-language-service-utils "^1.2.2"
graphql-language-service-parser@^0.1.14:
version "0.1.14"
resolved "https://registry.yarnpkg.com/graphql-language-service-parser/-/graphql-language-service-parser-0.1.14.tgz#dd25abda5dcff4f2268c9a19e026004271491661"
integrity sha512-72M4OksONeqT5slfdfODmlPBFlUQQkcnRhjgmPt9H2n8/DUcf4XzDkGXudBWpzNfjVU35+IADYW6x13wKw/fOg==
dependencies:
graphql-language-service-types "^0.1.14"
graphql-language-service-parser@^1.0.18, graphql-language-service-parser@^1.2.2: graphql-language-service-parser@^1.0.18, graphql-language-service-parser@^1.2.2:
version "1.5.2" version "1.5.2"
resolved "https://registry.yarnpkg.com/graphql-language-service-parser/-/graphql-language-service-parser-1.5.2.tgz#37deb56c16155cbd324fedef42ef9a3f0b38d723" resolved "https://registry.yarnpkg.com/graphql-language-service-parser/-/graphql-language-service-parser-1.5.2.tgz#37deb56c16155cbd324fedef42ef9a3f0b38d723"
@ -4907,11 +4892,6 @@ graphql-language-service-parser@^1.0.18, graphql-language-service-parser@^1.2.2:
graphql-config "2.2.1" graphql-config "2.2.1"
graphql-language-service-types "^1.5.2" graphql-language-service-types "^1.5.2"
graphql-language-service-types@^0.1.14:
version "0.1.14"
resolved "https://registry.yarnpkg.com/graphql-language-service-types/-/graphql-language-service-types-0.1.14.tgz#e6112785fc23ea8222f59a7f00e61b359f263c88"
integrity sha512-77KP83gvK0gWswvGY/+jx/GpsOfKuwWQ1AYnyPT2GDGG3//1QxQTObaZMAEevNTxJtO8T26YXxoUlqkvET7iEg==
graphql-language-service-types@^1.2.2, graphql-language-service-types@^1.5.2: graphql-language-service-types@^1.2.2, graphql-language-service-types@^1.5.2:
version "1.5.2" version "1.5.2"
resolved "https://registry.yarnpkg.com/graphql-language-service-types/-/graphql-language-service-types-1.5.2.tgz#bfd3b27a45dbc2457233c73cc1f8ff5da26795f8" resolved "https://registry.yarnpkg.com/graphql-language-service-types/-/graphql-language-service-types-1.5.2.tgz#bfd3b27a45dbc2457233c73cc1f8ff5da26795f8"