NewMutationMatcher constructs a new matcher for the provided mutation and variables. If the provided mutation is a string, it will be used-as-is, otherwise it will be converted to a string using the constructMutation function taken from shurcooL/graphql. The input parameter is a special form of var
(mutation any, input any, variables map[string]any, response GQLResponse)
| 41 | // to be used for later equality comparison, as when the http handler is called, the request body will no longer |
| 42 | // contain the input struct type information. |
| 43 | func NewMutationMatcher(mutation any, input any, variables map[string]any, response GQLResponse) Matcher { |
| 44 | mutationString, ok := mutation.(string) |
| 45 | if !ok { |
| 46 | // Matching shurcooL/githubv4 mutation behaviour found in https://github.com/shurcooL/githubv4/blob/48295856cce734663ddbd790ff54800f784f3193/githubv4.go#L45-L56 |
| 47 | if variables == nil { |
| 48 | variables = map[string]any{"input": input} |
| 49 | } else { |
| 50 | variables["input"] = input |
| 51 | } |
| 52 | |
| 53 | mutationString = constructMutation(mutation, variables) |
| 54 | m, _ := githubv4InputStructToMap(input) |
| 55 | variables["input"] = m |
| 56 | } |
| 57 | |
| 58 | return Matcher{ |
| 59 | Request: mutationString, |
| 60 | Variables: variables, |
| 61 | Response: response, |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | type GQLResponse struct { |
| 66 | Data map[string]any `json:"data"` |