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

Add a date type example? #27

Closed
AndrewRayCode opened this issue Mar 20, 2017 · 7 comments · Fixed by rmosolgo/graphql-ruby#1694
Closed

Add a date type example? #27

AndrewRayCode opened this issue Mar 20, 2017 · 7 comments · Fixed by rmosolgo/graphql-ruby#1694

Comments

@AndrewRayCode
Copy link

For a quickstart demo helper, it would be helpful for me to see how to define a date type and use it in a schema

@ghost
Copy link

ghost commented Dec 24, 2017

Any news on this?

@itsjimmyh
Copy link

would also like to know

@rmosolgo
Copy link
Owner

@dblock
Copy link

dblock commented Jul 22, 2018

Inspired from above.

Types::DateType = GraphQL::ScalarType.define do
  name 'Date'

  coerce_input ->(value, _ctx) { Time.zone.parse(value).to_date }
  coerce_result ->(value, _ctx) { value.iso8601 }
end

@dostu
Copy link

dostu commented Jul 22, 2018

GraphQL::Types::ISO8601DateTime recently got added to graphql-ruby.

Usage example:
field :created_at, GraphQL::Types::ISO8601DateTime, null: false

@dblock
Copy link

dblock commented Jul 23, 2018

I think we still need a Date, aka not a Date+Time type, no?

@bexuma
Copy link

bexuma commented Jan 15, 2019

You could use:
field :created_at, types.String

Which would have the following result:
"created_at": "2019-01-14 15:03:01 UTC"

On your client side you could have easily tailor the resulting field to serve your very needs.

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

Successfully merging a pull request may close this issue.

6 participants