shurcooL / githubv4

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing timestamps as variables

g14a opened this issue · comments

Hello!

I'm trying to construct a query to retrieve contribution calendar of a user and my query looks like the following as a struct.
I want to know how to pass a timestamp as a variable in cases of from and to. When I do the following I get an error saying

2020/08/05 17:36:33 ERROR: Variable $fromTime is declared by but not used, but the other variables are being passed normally.

Did anyone encounter this before?

My query looks like the following:

var StatsQuery struct {
	User struct {
		ContributionsCollection struct {
			ContributionCalendar ContributionCalendar
		} `graph:"contributionsCollection(from: $fromTime, to: $toTime)"`
	} `graphql:"user(login: $user)"`
}

I'm passing $fromTime and $toTime within a one year gap, in this format:

toTime := time.Now().Format(time.RFC3339)
fromTime := time.Now().AddDate(-1, 0, 0).Format(time.RFC3339)

My variables are in this format:

variables := map[string]interface{}{
		"user":          githubv4.String(user),
		"repoCount":     githubv4.Int(repoCount),
		"languageCount": githubv4.Int(languageCount),
		"fromTime":      githubv4.String(fromTime),
		"toTime":        githubv4.String(toTime),
	}

Thank you in advance :)

For the ContributionsCollection it expects a DateTime so I have set the values by converting time to a DateTime like this:

	"fromTime": githubv4.DateTime{Time: fromTime},
	"toTime":   githubv4.DateTime{Time: toTime},