Skip to content

Commit

Permalink
appease the linting gods
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 22, 2018
1 parent 7b6b124 commit d63128f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/...

4 changes: 2 additions & 2 deletions .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
5 changes: 4 additions & 1 deletion codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions codegen/templates/inliner/inliner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions handler/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), &params.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(&params); 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
Expand All @@ -82,21 +82,21 @@ 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
}

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)
}
Expand Down
16 changes: 8 additions & 8 deletions handler/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -129,13 +129,13 @@ func (c *wsConnection) run() {
}

func (c *wsConnection) subscribe(message *operationMessage) bool {
var params params
if err := json.Unmarshal(message.Payload, &params); 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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d63128f

Please sign in to comment.