alexsteinerde / graphql-kit

Easy setup of a GraphQL server with Vapor. It uses the GraphQL implementation of Graphiti.
MIT License
99 stars 18 forks source link

how to use @Timestamp model properties in graphql types #7

Closed jaredh159 closed 3 years ago

jaredh159 commented 3 years ago

Can you provide any input on how to expose @Timestamp model properties like createdAt, updatedAt, on graphql types? I tried just adding Scalar(Date.self) to my Schema, but I end up just getting numbers (like "createdAt": 648570561.42727697) in the json output.

After digging around a bit, I think I might need to somehow register a DateScalar with a Graphiti.DateFormatter, but I'm struggling to figure out where or how.

I debated opening this on the Swift Graphiti repo, but since it tied in directly with Vapor/Fluent, I thought maybe it might be appropriate here. But feel free to close if you think I should raise it over there instead.

Thanks again!

alexsteinerde commented 3 years ago

Please try to add the following line to your schema definition: DateScalar(formatter: ISO8601DateFormatter()). This will register a Date Scalar with the iso8601 date format. Does this work for you?

jaredh159 commented 3 years ago

Works great, that was simple. Thanks for your time. 👍