diff --git a/.circleci/config.yml b/.circleci/config.yml index a1d642f670..0b8e06eddd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,4 +16,5 @@ jobs: - run: go generate ./... && if [[ $(git --no-pager diff) ]] ; then echo "you need to run go generate" ; git --no-pager diff ; exit 1 ; fi - run: go vet ./... - run: go test -race ./... - - run: gometalinter --disable gocyclo ./example + - run: gometalinter ./example/... ./codegen/... ./handler/... + diff --git a/.gometalinter.json b/.gometalinter.json index 87e6f2b255..71b1eb26e6 100644 --- a/.gometalinter.json +++ b/.gometalinter.json @@ -2,11 +2,11 @@ "sort": ["path"], "Linters": { "errcheck": { - "Command": "errcheck -abspath -ignore '[rR]ead|[wW]rite'", + "Command": "errcheck -abspath -ignore '[rR]ead|[wW]rite|Close'", "Pattern": "PATH:LINE:COL:MESSAGE", "InstallFrom": "github.com/kisielk/errcheck", "PartitionStrategy": "packages" } }, - "Disable": ["gas","golint","gocyclo","goconst", "gotype"] + "Disable": ["gas","golint","gocyclo","goconst", "gotype", "maligned"] } diff --git a/codegen/object.go b/codegen/object.go index 91940bcb19..9bad02a0ca 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -150,7 +150,10 @@ func (os Objects) ByName(name string) *Object { func tpl(tpl string, vars map[string]interface{}) string { b := &bytes.Buffer{} - template.Must(template.New("inline").Parse(tpl)).Execute(b, vars) + err := template.Must(template.New("inline").Parse(tpl)).Execute(b, vars) + if err != nil { + panic(err) + } return b.String() } diff --git a/codegen/templates/inliner/inliner.go b/codegen/templates/inliner/inliner.go index 82fe4f04a9..cece75c1d9 100644 --- a/codegen/templates/inliner/inliner.go +++ b/codegen/templates/inliner/inliner.go @@ -39,9 +39,9 @@ func main() { out.WriteString("}\n") - formatted, err := imports.Process(dir+"data.go", out.Bytes(), nil) - if err != nil { - panic(err) + formatted, err2 := imports.Process(dir+"data.go", out.Bytes(), nil) + if err2 != nil { + panic(err2) } ioutil.WriteFile(dir+"data.go", formatted, 0644) diff --git a/handler/graphql.go b/handler/graphql.go index ddd71721a0..94fb87ef1c 100644 --- a/handler/graphql.go +++ b/handler/graphql.go @@ -52,25 +52,25 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc w.Header().Set("Content-Type", "application/json") - var params params + var reqParams params if r.Method == "GET" { - params.Query = r.URL.Query().Get("query") - params.OperationName = r.URL.Query().Get("operationName") + reqParams.Query = r.URL.Query().Get("query") + reqParams.OperationName = r.URL.Query().Get("operationName") if variables := r.URL.Query().Get("variables"); variables != "" { - if err := json.Unmarshal([]byte(variables), ¶ms.Variables); err != nil { + if err := json.Unmarshal([]byte(variables), &reqParams.Variables); err != nil { sendErrorf(w, http.StatusBadRequest, "variables could not be decoded") return } } } else { - if err := json.NewDecoder(r.Body).Decode(¶ms); err != nil { + if err := json.NewDecoder(r.Body).Decode(&reqParams); err != nil { sendErrorf(w, http.StatusBadRequest, "json body could not be decoded: "+err.Error()) return } } - doc, qErr := query.Parse(params.Query) + doc, qErr := query.Parse(reqParams.Query) if qErr != nil { sendError(w, http.StatusUnprocessableEntity, qErr) return @@ -82,7 +82,7 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc return } - op, err := doc.GetOperation(params.OperationName) + op, err := doc.GetOperation(reqParams.OperationName) if err != nil { sendErrorf(w, http.StatusUnprocessableEntity, err.Error()) return @@ -90,13 +90,13 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc switch op.Type { case query.Query: - b, err := json.Marshal(exec.Query(r.Context(), doc, params.Variables, op)) + b, err := json.Marshal(exec.Query(r.Context(), doc, reqParams.Variables, op)) if err != nil { panic(err) } w.Write(b) case query.Mutation: - b, err := json.Marshal(exec.Mutation(r.Context(), doc, params.Variables, op)) + b, err := json.Marshal(exec.Mutation(r.Context(), doc, reqParams.Variables, op)) if err != nil { panic(err) } diff --git a/handler/websocket.go b/handler/websocket.go index ce22e803ec..e85bced158 100644 --- a/handler/websocket.go +++ b/handler/websocket.go @@ -23,10 +23,10 @@ const ( stopMsg = "stop" // Client -> Server connectionAckMsg = "connection_ack" // Server -> Client connectionErrorMsg = "connection_error" // Server -> Client - connectionKeepAliveMsg = "ka" // Server -> Client dataMsg = "data" // Server -> Client errorMsg = "error" // Server -> Client completeMsg = "complete" // Server -> Client + //connectionKeepAliveMsg = "ka" // Server -> Client TODO: keepalives ) type operationMessage struct { @@ -129,13 +129,13 @@ func (c *wsConnection) run() { } func (c *wsConnection) subscribe(message *operationMessage) bool { - var params params - if err := json.Unmarshal(message.Payload, ¶ms); err != nil { + var reqParams params + if err := json.Unmarshal(message.Payload, &reqParams); err != nil { c.sendConnectionError("invalid json") return false } - doc, qErr := query.Parse(params.Query) + doc, qErr := query.Parse(reqParams.Query) if qErr != nil { c.sendError(message.ID, qErr) return true @@ -147,7 +147,7 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { return true } - op, err := doc.GetOperation(params.OperationName) + op, err := doc.GetOperation(reqParams.OperationName) if err != nil { c.sendError(message.ID, errors.Errorf("%s", err.Error())) return true @@ -156,9 +156,9 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { if op.Type != query.Subscription { var result *graphql.Response if op.Type == query.Query { - result = c.exec.Query(c.ctx, doc, params.Variables, op) + result = c.exec.Query(c.ctx, doc, reqParams.Variables, op) } else { - result = c.exec.Mutation(c.ctx, doc, params.Variables, op) + result = c.exec.Mutation(c.ctx, doc, reqParams.Variables, op) } c.sendData(message.ID, result) @@ -171,7 +171,7 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { c.active[message.ID] = cancel c.mu.Unlock() go func() { - next := c.exec.Subscription(ctx, doc, params.Variables, op) + next := c.exec.Subscription(ctx, doc, reqParams.Variables, op) for result := next(); result != nil; result = next() { fmt.Println(result) c.sendData(message.ID, result)