-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
476 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package transport | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
"github.com/vektah/gqlparser/gqlerror" | ||
) | ||
|
||
// SendError sends a best effort error to a raw response writer. It assumes the client can understand the standard | ||
// json error response | ||
func SendError(w http.ResponseWriter, code int, errors ...*gqlerror.Error) { | ||
w.WriteHeader(code) | ||
b, err := json.Marshal(&graphql.Response{Errors: errors}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
w.Write(b) | ||
} | ||
|
||
// SendErrorf wraps SendError to add formatted messages | ||
func SendErrorf(w http.ResponseWriter, code int, format string, args ...interface{}) { | ||
SendError(w, code, &gqlerror.Error{Message: fmt.Sprintf(format, args...)}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package transport | ||
|
||
type rawParams struct { | ||
Query string `json:"query"` | ||
OperationName string `json:"operationName"` | ||
Variables map[string]interface{} `json:"variables"` | ||
Extensions map[string]interface{} `json:"extensions"` | ||
} |
Oops, something went wrong.