{"modulePath":"github.com/github/github-mcp-server/v2","version":"v2.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubv4mock\n\ngithubv4mock package provides a mock GraphQL server used for testing queries produced via shurcooL/githubv4 or shurcooL/graphql modules.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n## Functions\n\n```go\nfunc NewMockedHTTPClient(ms ...Matcher) *http.Client\n```\nNewMockedHTTPClient creates a new HTTP client that registers a handler for /graphql POST requests. For each request, an attempt will be be made to match the request body against the provided matchers. If a match is found, the corresponding response will be returned with StatusOK.\n\nNote that query and variable matching can be slightly fickle. The client expects an EXACT match on the query, which in most cases will have been constructed from a type with graphql tags. The query construction code in shurcooL/githubv4 uses the field types to derive the query string, thus a go string is not the same as a graphql.ID, even though \\`type ID string\\`. It is therefore expected that matching variables have the right type for example:\n\n\tgithubv4mock.NewQueryMatcher(\n\t    struct {\n\t        Repository struct {\n\t            PullRequest struct {\n\t                 ID githubv4.ID\n\t            } `graphql:\"pullRequest(number: $prNum)\"`\n\t        } `graphql:\"repository(owner: $owner, name: $repo)\"`\n\t    }{},\n\t    map[string]any{\n\t        \"owner\": githubv4.String(\"owner\"),\n\t        \"repo\":  githubv4.String(\"repo\"),\n\t        \"prNum\": githubv4.Int(42),\n\t    },\n\t    githubv4mock.DataResponse(\n\t        map[string]any{\n\t            \"repository\": map[string]any{\n\t                \"pullRequest\": map[string]any{\n\t                     \"id\": \"PR_kwDODKw3uc6WYN1T\",\n\t                 },\n\t            },\n\t        },\n\t    ),\n\t)\n\nTo aid in variable equality checks, values are considered equal if they approximate to the same type. This is required because when the http handler is called, the request body no longer has the type information. This manifests particularly when using the githubv4.Input types which have type deffed fields in their structs. For example:\n\n\ttype CloseIssueInput struct {\n\t  IssueID ID `json:\"issueId\"`\n\t  StateReason *IssueClosedStateReason `json:\"stateReason,omitempty\"`\n\t}\n\nThis client does not currently provide a mechanism for out-of-band errors e.g. returning a 500, and errors are constrained to GQL errors returned in the response body with a 200 status code.\n\n```go\nfunc Ptr[T any](v T) *T\n```\n\n## Types\n\n```go\ntype GQLResponse struct {\n\tData   map[string]any `json:\"data\"`\n\tErrors []struct {\n\t\tMessage string `json:\"message\"`\n\t} `json:\"errors,omitempty\"`\n}\n```\n\n```go\nfunc DataResponse(data map[string]any) GQLResponse\n```\nDataResponse is the happy path response constructor for a mocked GraphQL request.\n\n```go\nfunc ErrorResponse(errorMsg string) GQLResponse\n```\nErrorResponse is the unhappy path response constructor for a mocked GraphQL request.\\\\ Note that for the moment it is only possible to return a single error message.\n\n```go\ntype Matcher struct {\n\tRequest   string\n\tVariables map[string]any\n\n\tResponse GQLResponse\n}\n```\n\n```go\nfunc NewMutationMatcher(mutation any, input any, variables map[string]any, response GQLResponse) Matcher\n```\nNewMutationMatcher 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.\n\nThe input parameter is a special form of variable, matching the usage in shurcooL/githubv4. It will be added to the query as a variable called \\`input\\`. Furthermore, it will be converted to a map\\[string]any to be used for later equality comparison, as when the http handler is called, the request body will no longer contain the input struct type information.\n\n```go\nfunc NewQueryMatcher(query any, variables map[string]any, response GQLResponse) Matcher\n```\nNewQueryMatcher constructs a new matcher for the provided query and variables. If the provided query is a string, it will be used-as-is, otherwise it will be converted to a string using the constructQuery function taken from shurcooL/graphql.\n\n","path":"github.com/github/github-mcp-server/v2/internal/githubv4mock","name":"githubv4mock","synopsis":"githubv4mock package provides a mock GraphQL server used for testing queries produced via shurcooL/githubv4 or shurcooL/graphql modules.","isRedistributable":true}
