-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grapühql connections for prefixes. #269
- Loading branch information
Martin Fenner
committed
May 11, 2019
1 parent
5475bd6
commit aa75fac
Showing
6 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class FacetType < BaseObject | ||
description "Summary information" | ||
|
||
field :id, String, null: true, description: "ID" | ||
field :title, String, null: true, description: "Title" | ||
field :count, Int, null: true, description: "Count" | ||
end |
26 changes: 26 additions & 0 deletions
26
app/graphql/types/prefix_connection_with_total_count_type.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class PrefixConnectionWithTotalCountType < GraphQL::Types::Relay::BaseConnection | ||
edge_type(PrefixEdgeType) | ||
|
||
field :total_count, Integer, null: false | ||
field :years, [FacetType], null: false | ||
|
||
def total_count | ||
object.nodes.size | ||
end | ||
|
||
def years | ||
if object.parent.class.name == "Provider" | ||
collection = object.parent.provider_prefixes.joins(:prefix) | ||
years = collection.where.not(prefixes: nil).order("YEAR(allocator_prefixes.created_at) DESC").group("YEAR(allocator_prefixes.created_at)").count | ||
years.map { |k,v| { id: k.to_s, title: k.to_s, count: v } } | ||
elsif object.parent.class.name == "Client" | ||
collection = object.parent.client_prefixes.joins(:prefix) | ||
years = collection.where.not(prefixes: nil).order("YEAR(datacentre_prefixes.created_at) DESC").group("YEAR(datacentre_prefixes.created_at)").count | ||
years.map { |k,v| { id: k.to_s, title: k.to_s, count: v } } | ||
else | ||
{} | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class PrefixEdgeType < GraphQL::Types::Relay::BaseEdge | ||
node_type(PrefixType) | ||
end |
This file contains 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
This file contains 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