1
- // Generated from <%= script_name %>
1
+ //
2
+ // <%= type.name %> .swift
3
+ // Buy
4
+ //
5
+ // Created by Shopify.
6
+ // Copyright (c) 2017 Shopify Inc. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ // of this software and associated documentation files (the "Software"), to deal
10
+ // in the Software without restriction, including without limitation the rights
11
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ // copies of the Software, and to permit persons to whom the Software is
13
+ // furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in
16
+ // all copies or substantial portions of the Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ // THE SOFTWARE.
25
+ //
26
+
2
27
import Foundation
3
28
<% if import_graphql_support %>
4
29
import GraphQLSupport
5
30
<% end %>
6
31
7
32
<% if type.interface? || type.union? %>
33
+ <%= %>
34
+ <%= swift_doc(type) %>
8
35
public protocol <%= type.name %> {
9
36
var typeName: String { get }
10
37
<% type.fields(include_deprecated: true).each do |field| %>
11
38
<%= swift_attributes(field) %>
12
39
var <%= escape_reserved_word(field.camelize_name) %> : <%= swift_output_type(field.type) %> { get }
13
40
<% end %>
14
41
func childResponseObjectMap() - > [GraphQL.AbstractResponse]
15
-
16
42
func responseObject() -> GraphQL.AbstractResponse
17
43
}
18
44
<% end %>
19
45
20
46
extension <%= schema_name %> {
21
47
<% case type . kind ; when 'OBJECT' , 'INTERFACE' , 'UNION' %>
48
+ <%= swift_doc ( type ) %>
22
49
open class <%= type . name %> Query: GraphQL.AbstractQuery, GraphQLQuery {
23
50
public typealias Response = <%= type . name %>
24
51
@@ -28,8 +55,8 @@ extension <%= schema_name %> {
28
55
}
29
56
<% end %>
30
57
<% type . fields ( include_deprecated : true ) . each do |field | %>
31
- <%= swift_attributes ( field ) %>
32
- @discardableResult
58
+ <%= swift_doc ( field ) %>
59
+ <%= swift_attributes ( field ) %> @discardableResult
33
60
open func <%= escape_reserved_word ( field . camelize_name ) %> (<%= swift_arg_defs ( field ) %> ) -> <%= type . name %> Query {
34
61
<% unless field . args . empty? %>
35
62
var args: [String] = []
@@ -53,7 +80,7 @@ extension <%= schema_name %> {
53
80
subfields(subquery)
54
81
<% end %>
55
82
56
- addField(field: "<%= field . name %> ", aliasSuffix: aliasSuffix <% unless field . args . empty? %> , args: argsString<% end %> <% if field . subfields? %> , subfields: subquery<% end %> )
83
+ addField(field: "<%= field . name %> ", aliasSuffix: alias <% unless field . args . empty? %> , args: argsString<% end %> <% if field . subfields? %> , subfields: subquery<% end %> )
57
84
return self
58
85
}
59
86
<% end %>
@@ -76,10 +103,11 @@ extension <%= schema_name %> {
76
103
77
104
<% class_name = type . object? ? type . name : "Unknown#{ type . name } " %>
78
105
<% protocols = type . object? ? type . interfaces . map { |iface | ", #{ iface . name } " } . join : ", #{ type . name } " %>
106
+ <%= swift_doc ( type ) %>
79
107
open class <%= class_name %> : GraphQL.AbstractResponse, GraphQLObject<%= protocols %> {
80
108
public typealias Query = <%= type . name %> Query
81
109
82
- open override func deserializeValue(fieldName: String, value: Any) throws -> Any? {
110
+ internal override func deserializeValue(fieldName: String, value: Any) throws -> Any? {
83
111
let fieldValue = value
84
112
switch fieldName {
85
113
<% type . fields ( include_deprecated : true ) . each do |field | %>
@@ -92,7 +120,7 @@ extension <%= schema_name %> {
92
120
}
93
121
94
122
<% if type . object? %>
95
- open var typeName: String { return "<%= type . name %> " }
123
+ open let typeName = "<%= type . name %> "
96
124
<% else %>
97
125
open var typeName: String { return field(field: "__typename") as! String }
98
126
@@ -102,8 +130,7 @@ extension <%= schema_name %> {
102
130
}
103
131
switch typeName {
104
132
<% type . possible_types . each do |possible_type | %>
105
- case "<%= possible_type . name %> ":
106
- return try <%= possible_type . name %> .init(fields: fields)
133
+ case "<%= possible_type . name %> ": return try <%= possible_type . name %> .init(fields: fields)
107
134
<% end %>
108
135
default:
109
136
return try <%= class_name %> .init(fields: fields)
@@ -119,44 +146,32 @@ extension <%= schema_name %> {
119
146
120
147
<% unless field . args . empty? %>
121
148
<%= swift_attributes ( field ) %>
122
- open func aliased<%= field . classify_name %> (aliasSuffix : String) -> <%= swift_output_type ( field . type ) %> {
123
- return internalGet<%= field . classify_name %> (aliasSuffix: aliasSuffix )
149
+ open func aliased<%= field . classify_name %> (alias : String) -> <%= swift_output_type ( field . type ) %> {
150
+ return internalGet<%= field . classify_name %> (alias: alias )
124
151
}
125
152
<% end %>
126
153
127
- func internalGet<%= field . classify_name %> (aliasSuffix : String? = nil) -> <%= swift_output_type ( field . type ) %> {
128
- return field(field: "<%= field . name %> ", aliasSuffix: aliasSuffix ) as! <%= swift_output_type ( field . type ) %>
154
+ func internalGet<%= field . classify_name %> (alias : String? = nil) -> <%= swift_output_type ( field . type ) %> {
155
+ return field(field: "<%= field . name %> ", aliasSuffix: alias ) as! <%= swift_output_type ( field . type ) %>
129
156
}
130
157
<% end %>
131
158
132
- override open func childObjectType(key: String) -> GraphQL.ChildObjectType {
159
+ override internal func childObjectType(key: String) -> GraphQL.ChildObjectType {
133
160
switch(key) {
134
161
<% type . fields ( include_deprecated : true ) . each do |field | %>
135
- case "<%= field . name %> ":
136
- <% if [ 'OBJECT' , 'INTERFACE' ] . include? ( field . type . unwrap_non_null . kind ) %>
137
- return .Object
138
- <% elsif field . type . unwrap_non_null . kind == 'LIST' && [ 'OBJECT' , 'INTERFACE' ] . include? ( field . type . unwrap . kind ) %>
139
- return .ObjectList
140
- <% elsif field . type . unwrap_non_null . kind == 'LIST' && field . type . unwrap . kind != 'OBJECT' %>
141
- return .ScalarList
142
- <% else %>
143
- return .Scalar
144
- <% end %>
162
+ case "<%= field . name %> ": <%= child_object_return_value ( field . type . unwrap_non_null . kind ) %>
145
163
<% end %>
146
- default:
147
- return .Scalar
164
+ default: return .Scalar
148
165
}
149
166
}
150
167
151
- override open func fetchChildObject(key: String) -> GraphQL.AbstractResponse? {
168
+ override internal func fetchChildObject(key: String) -> GraphQL.AbstractResponse? {
152
169
switch(key) {
153
170
<% type . fields ( include_deprecated : true ) . each do |field | %>
154
171
<% if field . type . unwrap_non_null . kind == 'OBJECT' %>
155
- case "<%= field . name %> ":
156
- return internalGet<%= field . classify_name %> ()
172
+ case "<%= field . name %> ": return internalGet<%= field . classify_name %> ()
157
173
<% elsif field . type . unwrap_non_null . kind == 'INTERFACE' %>
158
- case "<%= field . name %> ":
159
- return internalGet<%= field . classify_name %> ()<%= field . type . non_null? ? '' : '?' %> .responseObject()
174
+ case "<%= field . name %> ": return internalGet<%= field . classify_name %> ()<%= field . type . non_null? ? '' : '?' %> .responseObject()
160
175
<% end %>
161
176
<% end %>
162
177
default:
@@ -165,7 +180,7 @@ extension <%= schema_name %> {
165
180
return nil
166
181
}
167
182
168
- override open func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] {
183
+ override internal func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] {
169
184
switch(key) {
170
185
<% type . fields ( include_deprecated : true ) . each do |field | %>
171
186
<% if field . type . unwrap_non_null . kind == 'LIST' && field . type . unwrap . kind == 'OBJECT' %>
@@ -205,6 +220,7 @@ extension <%= schema_name %> {
205
220
}
206
221
}
207
222
<% when 'INPUT_OBJECT' %>
223
+ <%= swift_doc ( type ) %>
208
224
open class <%= type . name %> {
209
225
<% type . input_fields . each do |field | %>
210
226
open var <%= escape_reserved_word ( field . camelize_name ) %> : <%= swift_input_type ( field . type ) %>
@@ -238,10 +254,11 @@ extension <%= schema_name %> {
238
254
}
239
255
}
240
256
<% when 'ENUM' %>
257
+ <%= swift_doc ( type ) %>
241
258
public enum <%= type . name %> : String {
242
259
<% type . enum_values . each do |value | %>
243
- <%= swift_attributes ( value ) %>
244
- case <%= escape_reserved_word ( value . camelize_name ) %> = "<%= value . name %> "
260
+ <%= swift_doc ( value ) %>
261
+ <%= swift_attributes ( value ) %> case <%= escape_reserved_word ( value . camelize_name ) %> = "<%= value . name %> "
245
262
<% end %>
246
263
case unknownValue = ""
247
264
}
0 commit comments