Skip to content

Instantly share code, notes, and snippets.

@goodpic
Created April 24, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodpic/5a59cd95fa680cfae715cf3bc581cbe7 to your computer and use it in GitHub Desktop.
Save goodpic/5a59cd95fa680cfae715cf3bc581cbe7 to your computer and use it in GitHub Desktop.
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