-
Notifications
You must be signed in to change notification settings - Fork 255
/
query_type.rb
119 lines (97 loc) · 3.63 KB
/
query_type.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module Types
class QueryType < Types::BaseObject
# Add `node(id: ID!) and `nodes(ids: [ID!]!)`
include GraphQL::Types::Relay::HasNodeField
include GraphQL::Types::Relay::HasNodesField
# Add root-level fields here.
# They will be entry points for queries on your schema.
# # TODO: remove me
# field :test_field, String, null: false,
# description: "An example field added by the generator"
# def test_field
# "Hello World!"
# end
# field :all_pages, [Types::PageType], null: false, description: "Get all the page items."
field :page, Types::PageType, null: false do
description "Get a page item based on id."
argument :id, ID, required: true
end
def page(id:)
Page.find(id)
end
field :find_page, Types::PageType, null: true do
description "Get a page based on slug."
argument :slug, String, required: true
argument :locale, String, required: true
end
def find_page(slug:, locale:)
I18n.locale = locale
Pwb::Page.find_by_slug(slug)
end
field :search_properties, [Types::PropertyType], null: false do
description "Search for properties"
argument :sale_or_rental, String, required: false, default_value: "sale"
argument :currency, String, required: false, default_value: "usd"
argument :for_sale_price_from, String, required: false, default_value: "none"
argument :for_sale_price_till, String, required: false, default_value: "none"
argument :for_rent_price_from, String, required: false, default_value: "none"
argument :for_rent_price_till, String, required: false, default_value: "none"
argument :bedrooms_from, String, required: false, default_value: "none"
argument :bathrooms_from, String, required: false, default_value: "none"
end
def search_properties(**args)
# I18n.locale = "es"
Pwb::Prop.properties_search(**args)
end
field :get_translations, Types::TranslationType, null: true do
description "Get translations for a locale."
argument :locale, String, required: true
end
def get_translations(locale:)
return {
locale: locale,
result: I18n.t(".", locale: locale),
}
end
field :get_links, [Types::LinkType], null: false do
description "Return a list of links"
argument :placement, String
end
def get_links(placement:)
Pwb::Link.where(placement: placement)
end
field :get_top_nav_links, [Types::LinkType], null: false do
description "Get top nav links for a locale."
argument :locale, String, required: true
end
def get_top_nav_links(locale:)
I18n.locale = locale
Pwb::Link.where(placement: "top_nav").where(visible: true)
end
field :get_footer_links, [Types::LinkType], null: false do
description "Get top nav links for a locale."
argument :locale, String, required: true
end
def get_footer_links(locale:)
I18n.locale = locale
Pwb::Link.where(placement: "footer").where(visible: true)
end
field :get_site_details, Types::WebsiteType, null: false do
description "Get site details."
argument :locale, String, required: true
end
def get_site_details(locale:)
I18n.locale = locale
Pwb::Website.unique_instance
end
field :find_property, Types::PropertyType, null: true do
description "Get a property based on id."
argument :id, String, required: true
argument :locale, String, required: true
end
def find_property(id:, locale:)
I18n.locale = locale
Pwb::Prop.find(id)
end
end
end