-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.go
63 lines (56 loc) · 2.07 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hasura_api
import (
"fmt"
"github.com/minskylab/hasura-api/metadata"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func (r *MetadataClient) genericHasuraQuery(body metadata.MetadataQuery) (metadata.MetadataResponse, error) {
endpoint := fmt.Sprintf("%s/v1/metadata", r.Config.Endpoint)
logrus.Debug("sending hasura metadata query: ", body.Type)
res, err := r.client.R().
SetHeaders(map[string]string{
"Content-Type": "application/json",
"X-Hasura-Role": "admin",
"X-Hasura-Admin-Secret": r.adminSecret,
}).
SetBody(body).
Post(endpoint)
if err != nil {
return nil, errors.WithStack(err)
}
return metadata.RestyResponse{Response: res}, nil
// switch res.StatusCode() {
// case 200, 201:
// switch successRes := res.Result().(type) {
// case metadata.ObjectResponse, metadata.ArrayResponse:
// return successRes.(metadata.MetadataResponse), nil
// default:
// return nil, errors.Errorf("unexpected success response: %v", res.Result())
// }
// case 400:
// switch badRequestRes := res.Result().(type) {
// case metadata.BadRequestResponse, metadata.ArrayResponse:
// return badRequestRes.(metadata.MetadataResponse), nil
// default:
// return nil, errors.Errorf("unexpected bad request response: %v", res.Result())
// }
// case 401:
// switch unauthorizedRes := res.Result().(type) {
// case metadata.UnauthorizedResponse, metadata.ArrayResponse:
// return unauthorizedRes.(metadata.MetadataResponse), nil
// default:
// return nil, errors.Errorf("unexpected unauthorized response: %v", res.Result())
// }
// case 500:
// switch internalServerErrorRes := res.Result().(type) {
// case metadata.InternalServerErrorResponse, metadata.ArrayResponse:
// return internalServerErrorRes.(metadata.MetadataResponse), nil
// default:
// return nil, errors.Errorf("unexpected internal server error response: %v", res.Result())
// }
// default:
// logrus.Warnf("unexpected response (code: %d): %v", res.StatusCode(), res.Result())
// return res.Result().(metadata.MetadataResponse), nil
// }
}