-
I am trying to run following query:
This is what I got so far: func GetUserByUsername(username string, c *http.Client) (string, error) {
input := models.UserQueryId{}
input.Users.Filter.Username.ILike = username
client := graphql.NewClient(tools.GetGraphqlUrl(), c)
err := client.Query(context.Background(), &models.GetUserByIdQueryResponse, nil)
if err != nil {
return "", logging.Problem(section, "problem getting all apps", err)
}
userId := models.GetUserByIdQueryResponse.Users.Nodes[0].User_id
if len(userId) < 6 {
return "", fmt.Errorf("user id is to short, got: %s", userId)
}
log.Printf("\"%s\" user id is: \"%s\"\n", username, userId)
return userId, nil
} Models: type UserQueryId struct {
Users struct {
Filter struct {
Username struct {
ILike string `json:"iLike"`
}
}
}
}
var GetUserByIdQueryResponse struct {
Users struct {
Nodes []struct {
User_id string `json:"user_id"`
}
} `graphql:"users(filter: $filter)"`
} Running that, I am getting:
Could someone please help me how to create a filter query :) |
Beta Was this translation helpful? Give feedback.
Answered by
dthisner
Apr 5, 2022
Replies: 1 comment
-
Got it to work, needed to make sure that I was specifying the String as func GetUserByUsername(username string, c *http.Client) (string, error) {
client := graphql.NewClient(tools.GetGraphqlUrl(), c)
err := client.Query(context.Background(), &models.GetUserByUsernameResponse, map[string]interface{}{"iLike": graphql.String(username)})
if err != nil {
return "", logging.Problem(section, "problem getting user", err)
}
userId := models.GetUserByUsernameResponse.Users.Nodes[0].User_id
if len(userId) < 6 {
return "", fmt.Errorf("user id is to short, got: %s", userId)
}
log.Printf("\"%s\" user id is: \"%s\"\n", username, userId)
return userId, nil
} var GetUserByUsernameResponse struct {
Users struct {
Nodes []struct {
User_id string
}
} `graphql:"users(filter: { username: { iLike: $iLike } })"`
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dthisner
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it to work, needed to make sure that I was specifying the String as
graphql.String
, otherwise it thought it wasID
Final code: