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

More time formats #23

Closed
Teddy-Schmitz opened this issue Feb 23, 2018 · 3 comments
Closed

More time formats #23

Teddy-Schmitz opened this issue Feb 23, 2018 · 3 comments

Comments

@Teddy-Schmitz
Copy link

Hey, thanks for getting custom types in so quickly!
I was wondering if you could extend your built-in Time scalar to support more formats similar to the one in neelance's library.

Not sure if there was a particular reason or not you didn't want to do this. If your ok with this I can open an MR for it.

From neelance/graphql-go

func (t *Time) UnmarshalGraphQL(input interface{}) error {
	switch input := input.(type) {
	case time.Time:
		t.Time = input
		return nil
	case string:
		var err error
		t.Time, err = time.Parse(time.RFC3339, input)
		return err
	case int:
		t.Time = time.Unix(int64(input), 0)
		return nil
	case float64:
		t.Time = time.Unix(int64(input), 0)
		return nil
	default:
		return fmt.Errorf("wrong type")
	}
}
@vektah
Copy link
Collaborator

vektah commented Feb 23, 2018

Personally I feel like being stricter is better, but I could be swayed by some good use cases?

You can of course overwrite the provided time scalar implementation with your own by defining a custom scalar and setting it in types.json.

@Teddy-Schmitz
Copy link
Author

ya thats exactly what im doing, right now. As for my own use case it would just make it so I don't need to implement it myself. But if you prefer it to be strict thats also ok in my book.

I have the times stored as integers in the DB (thats how I get them) but going out through graph I prefer it to be the RFC3339 string so thats why this would work better for me.

@imiskolee
Copy link

@Teddy-Schmitz @vektah
you need define custom scalar type if you need more time formats.i don't want this feature into gqlgen.

@vektah vektah closed this as completed Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants