Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing timestamps as variables #75

Open
g14a opened this issue Aug 5, 2020 · 1 comment
Open

Passing timestamps as variables #75

g14a opened this issue Aug 5, 2020 · 1 comment

Comments

@g14a
Copy link

g14a commented Aug 5, 2020

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 :)

@jeff1010322
Copy link

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},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants