@@ -200,6 +200,28 @@ local function field_to_avro(object_type, fields, context)
200
200
201
201
local fieldTypeAvro = gql_type_to_avro (fieldType .kind , subSelections ,
202
202
context )
203
+ -- Currently we support only 'include' and 'skip' directives. Both of them
204
+ -- affect resulting avro-schema the same way: field with directive becomes
205
+ -- nullable, if it's already not. Nullable field does not change.
206
+ --
207
+ -- If it is a 1:N connection then it's 'array' field becomes 'array*'.
208
+ -- If it is avro-schema union, then 'null' will be added to the union
209
+ -- types. If there are more then one directive on a field then all works
210
+ -- the same way, like it is only one directive. (But we still check all
211
+ -- directives to be 'include' or 'skip').
212
+ if firstField .directives ~= nil then
213
+ for _ , d in ipairs (firstField .directives ) do
214
+ check (d .name , " directive.name" , " table" )
215
+ check (d .arguments , " directive.arguments" , " table" )
216
+ check (d .kind , " directive.kind" , " string" )
217
+ assert (d .kind == " directive" )
218
+ check (d .name .value , " directive.name.value" , " string" )
219
+ assert (d .name .value == " include" or d .name .value == " skip" ,
220
+ " Only 'include' and 'skip' directives are supported for now" )
221
+ end
222
+ fieldTypeAvro = avro_helpers .make_avro_type_nullable (fieldTypeAvro )
223
+ end
224
+
203
225
return {
204
226
name = convert_schema_helpers .base_name (fieldName ),
205
227
type = fieldTypeAvro ,
0 commit comments