| 62 | } |
| 63 | |
| 64 | func GraphQLMutationMatcher(q string, cb func(map[string]interface{}) bool) Matcher { |
| 65 | re := regexp.MustCompile(q) |
| 66 | |
| 67 | return func(req *http.Request) bool { |
| 68 | if !strings.EqualFold(req.Method, "POST") { |
| 69 | return false |
| 70 | } |
| 71 | if req.URL.Path != "/graphql" && req.URL.Path != "/api/graphql" { |
| 72 | return false |
| 73 | } |
| 74 | |
| 75 | var bodyData struct { |
| 76 | Query string |
| 77 | Variables struct { |
| 78 | Input map[string]interface{} |
| 79 | } |
| 80 | } |
| 81 | _ = decodeJSONBody(req, &bodyData) |
| 82 | |
| 83 | if re.MatchString(bodyData.Query) { |
| 84 | return cb(bodyData.Variables.Input) |
| 85 | } |
| 86 | |
| 87 | return false |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func QueryMatcher(method string, path string, query url.Values) Matcher { |
| 92 | return func(req *http.Request) bool { |