Created
April 24, 2018 17:31
-
-
Save goodpic/5a59cd95fa680cfae715cf3bc581cbe7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Types | |
# Product schema | |
class ProductType < GraphQL::Schema::Object | |
# Name of this Type | |
graphql_name 'Product' | |
field :sales_history, [Types::SalesHistoryType], | |
null: true, | |
resolve: ->(product, args, ctx) { | |
days = ctx.irep_node.parent.arguments.days || 7 | |
since = Date.today - days | |
[ | |
product.department_daily_sales | |
.where('invoiced_on >= ? ', since) | |
.order(:invoiced_on) | |
] | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment