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

Commit 9903306

Browse files
committed
Fix introspection: GraphiQL works
Fixes #179.
1 parent 143c35e commit 9903306

File tree

5 files changed

+3147
-14
lines changed

5 files changed

+3147
-14
lines changed

graphql/convert_schema/arguments.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function arguments.convert_record_fields(fields, root_name)
127127

128128
local context = {
129129
field_name = nil,
130-
path = {'$arguments', root_name},
130+
path = {'arguments', root_name},
131131
}
132132

133133
local args = {}

graphql/convert_schema/helpers.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local check = utils.check
33

44
local helpers = {}
55

6-
--- Get dot-separated name prepended with namespace.
6+
--- Get three-underscore-separated name prepended with namespace.
77
---
88
--- @tparam string name base name
99
---
@@ -19,18 +19,18 @@ function helpers.full_name(name, context)
1919
return name
2020
end
2121

22-
local namespace = table.concat(context.path, '.')
23-
return namespace .. '.' .. name
22+
local namespace = table.concat(context.path, '___')
23+
return namespace .. '___' .. name
2424
end
2525

26-
--- Get last part of dot-separated name.
26+
--- Get last part of three-underscore-separated name.
2727
---
2828
--- @tparam string name full name
2929
---
3030
--- @treturn string base name
3131
function helpers.base_name(name)
3232
check(name, 'name', 'string')
33-
return name:gsub('^.*%.', '')
33+
return name:gsub('^.*___', '')
3434
end
3535

3636
return helpers

graphql/core/types.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ end
225225

226226
function types.inputMap(config)
227227
local instance = {
228-
__type = 'InputMap',
228+
__type = 'Scalar',
229+
subtype = 'InputMap',
229230
name = config.name,
230231
serialize = function(value) return value end,
231232
parseValue = function(value) return value end,
@@ -243,7 +244,8 @@ end
243244

244245
function types.inputUnion(config)
245246
local instance = {
246-
__type = 'InputUnion',
247+
__type = 'Scalar',
248+
subtype = 'InputUnion',
247249
name = config.name,
248250
serialize = function(value) return value end,
249251
parseValue = function(value) return value end,

graphql/core/util.lua

+11-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ function util.coerceValue(node, schemaType, variables)
7171
end
7272

7373
local isInputObject = schemaType.__type == 'InputObject'
74-
if isInputObject or schemaType.__type == 'InputMap' then
74+
local isInputMap = schemaType.__type == 'Scalar' and
75+
schemaType.subtype == 'InputMap'
76+
local isInputUnion = schemaType.__type == 'Scalar' and
77+
schemaType.subtype == 'InputUnion'
78+
79+
if isInputObject or isInputMap then
7580
if node.kind ~= 'inputObject' then
7681
error('Expected an input object')
7782
end
@@ -102,18 +107,18 @@ function util.coerceValue(node, schemaType, variables)
102107
return node.value
103108
end
104109

110+
if isInputUnion then
111+
local child_type = schemaType.resolveNodeType(node)
112+
return util.coerceValue(node, child_type, variables)
113+
end
114+
105115
if schemaType.__type == 'Scalar' then
106116
if schemaType.parseLiteral(node) == nil then
107117
error('Could not coerce "' .. tostring(node.value) .. '" to "' .. schemaType.name .. '"')
108118
end
109119

110120
return schemaType.parseLiteral(node)
111121
end
112-
113-
if schemaType.__type == 'InputUnion' then
114-
local child_type = schemaType.resolveNodeType(node)
115-
return util.coerceValue(node, child_type, variables)
116-
end
117122
end
118123

119124
return util

0 commit comments

Comments
 (0)