Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 286cb8d

Browse files
committed
Add creation of avro-schema from query with directives
Close #85
1 parent ce7faca commit 286cb8d

File tree

2 files changed

+559
-0
lines changed

2 files changed

+559
-0
lines changed

graphql/query_to_avro.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ local function field_to_avro(object_type, fields, context)
200200

201201
local fieldTypeAvro = gql_type_to_avro(fieldType.kind, subSelections,
202202
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+
203225
return {
204226
name = convert_schema_helpers.base_name(fieldName),
205227
type = fieldTypeAvro,

0 commit comments

Comments
 (0)