MCPcopy
hub / github.com/mislav/hub / GraphQL

Method GraphQL

github/client.go:892–928  ·  view source on GitHub ↗

GraphQL facilitates performing a GraphQL request and parsing the response

(query string, variables interface{}, data interface{})

Source from the content-addressed store, hash-verified

890
891// GraphQL facilitates performing a GraphQL request and parsing the response
892func (client *Client) GraphQL(query string, variables interface{}, data interface{}) error {
893 api, err := client.simpleApi()
894 if err != nil {
895 return err
896 }
897
898 payload := map[string]interface{}{
899 "query": query,
900 "variables": variables,
901 }
902 resp, err := api.PostJSON("graphql", payload)
903 if err = checkStatus(200, "performing GraphQL", resp, err); err != nil {
904 return err
905 }
906
907 responseData := struct {
908 Data interface{}
909 Errors []struct {
910 Message string
911 }
912 }{
913 Data: data,
914 }
915 err = resp.Unmarshal(&responseData)
916 if err != nil {
917 return err
918 }
919
920 if len(responseData.Errors) > 0 {
921 messages := []string{}
922 for _, e := range responseData.Errors {
923 messages = append(messages, e.Message)
924 }
925 return fmt.Errorf("API error: %s", strings.Join(messages, "; "))
926 }
927 return nil
928}
929
930func (client *Client) CurrentUser() (user *User, err error) {
931 api, err := client.simpleApi()

Callers 1

transferIssueFunction · 0.95

Calls 5

simpleApiMethod · 0.95
checkStatusFunction · 0.85
PostJSONMethod · 0.80
UnmarshalMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected