Skip to content

add support for GraphQL Docs Request for client request, add fix can'… #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion graphql/introspection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ __Directive = types.object({
args = {
kind = types.nonNull(types.list(types.nonNull(__InputValue))),
resolve = resolveArgs
},

onOperation = {
kind = types.boolean,
defaultValue = false
},
onFragment = {
kind = types.boolean,
defaultValue = false
},
onField = {
kind = types.boolean,
defaultValue = false
}
}
end
Expand Down Expand Up @@ -230,7 +243,7 @@ __Type = types.object({
kind = types.list(types.nonNull(__Type)),
resolve = function(kind)
if kind.__type == 'Object' then
return kind.interfaces
return kind.interface or {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still be .interfaces?

end
end
},
Expand Down
11 changes: 9 additions & 2 deletions graphql/rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,17 @@ function rules.variablesAreUsed(node, context)
end

function rules.variablesAreDefined(node, context)
if context.variableReferences then
local _cv = context.variableReferences
if _cv then
local variableMap = {}
local _vn
for _, definition in ipairs(node.variableDefinitions or {}) do
variableMap[definition.variable.name.value] = true
_vn = definition.variable.name.value
variableMap[_vn] = true
-- TODO Maybe danger
if not _cv[_vn] then
_cv[_vn] = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leads to a regression where unused variables don't fail validation anymore, try validating query test($arg: String) {}.

end
end

for variable in pairs(context.variableReferences) do
Expand Down
9 changes: 8 additions & 1 deletion graphql/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ function util.map(t, fn)
return res
end

function util.map_input(t, fn)
local res = {}
for _i, field in pairs(t) do res[field.name] = fn(field) end
return res
end

function util.find(t, fn)
local res = {}
for k, v in pairs(t) do
Expand Down Expand Up @@ -75,7 +81,8 @@ function util.coerceValue(node, schemaType, variables)
error('Expected an input object')
end

return util.map(node.values, function(field)
-- You can get InputTypes`s parameters now, just as input.name
return util.map_input(node.values, function(field)
if not schemaType.fields[field.name] then
error('Unknown input object field "' .. field.name .. '"')
end
Expand Down
4 changes: 2 additions & 2 deletions graphql/validate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ local visitors = {
rules.variablesHaveCorrectType,
rules.variableDefaultValuesHaveCorrectType,
exit = {
rules.variablesAreUsed,
rules.variablesAreDefined
rules.variablesAreDefined,
rules.variablesAreUsed
}
}
},
Expand Down