Skip to content

Add availability of description field in any object/inputObject arguments #22

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

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:

- name: Install dependencies
run: |
tarantoolctl rocks install luatest 0.5.2
tarantoolctl rocks install luacheck 0.25.0
tarantoolctl rocks install luatest 0.5.5
tarantoolctl rocks install luacheck 0.26.0
tarantoolctl rocks make

- name: Run linter
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
.doctrees
__pycache__
/dev
/tmp
/tmp/*
!/tmp/.keep
doc
release
release-doc
Expand All @@ -27,4 +28,5 @@ luacov.*.out*
/package-lock.json
*.mo
.history
.vscode
*.rock

6 changes: 6 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
statsfile = 'tmp/luacov.stats.out'
reportfile = 'tmp/luacov.report.out'
exclude = {
'/test/',
'/tmp/',
}
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SHELL := /bin/bash

.PHONY: .rocks
.rocks: graphql-scm-1.rockspec Makefile
tarantoolctl rocks make
tarantoolctl rocks install luatest 0.5.5
tarantoolctl rocks install luacov 0.13.0
tarantoolctl rocks install luacheck 0.26.0

.PHONY: lint
lint:
if [ ! -d ".rocks" ]; then make .rocks; fi
.rocks/bin/luacheck .

.PHONY: test
test: lint
rm -f tmp/luacov*
.rocks/bin/luatest --verbose --coverage --shuffle group
.rocks/bin/luacov . && grep -A999 '^Summary' tmp/luacov.report.out

.PHONY: clean
clean:
rm -rf .rocks

.PHONY: build
build:
if [ ! -d ".rocks" ]; then make .rocks; fi
tarantoolctl rocks make
tarantoolctl rocks pack graphql scm-1
53 changes: 44 additions & 9 deletions graphql/execute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ local function collectFields(objectType, selections, visitedFragments, result, c
end

local evaluateSelections
local serializemap = {__serialize='map'}
local serializemap = {__serialize='map',}

local function completeValue(fieldType, result, subSelections, context, opts)
local fieldName = opts and opts.fieldName or '???'
Expand Down Expand Up @@ -260,6 +260,7 @@ local function getFieldEntry(objectType, object, fields, context)

local arguments = util.map(fieldType.arguments or {}, function(argument, name)
local supplied = argumentMap[name] and argumentMap[name].value
if argument.kind then argument = argument.kind end
return util.coerceValue(supplied, argument, context.variables, {
strict_non_null = true,
defaultValues = defaultValues,
Expand All @@ -278,13 +279,47 @@ local function getFieldEntry(objectType, object, fields, context)
if argument and argument.value then
positions[pos] = {
name=argument.name.value,
value=arguments[argument.name.value]
value=arguments[argument.name.value],
}
pos = pos + 1
end
end

arguments = setmetatable(arguments, {__index=positions})
arguments = setmetatable(arguments, {__index=positions,})

local directiveMap = {}
for _, directive in ipairs(firstField.directives or {}) do
directiveMap[directive.name.value] = directive
end

local directives = {}
local directivesDefaultValues = {}

if next(directiveMap) then
util.map_name(context.schema.directives or {}, function(directive, directive_name)
local supplied_directive = directiveMap[directive_name]
if supplied_directive ~= nil then
local directiveArgumentMap = {}
for _, argument in ipairs(supplied_directive.arguments or {}) do
directiveArgumentMap[argument.name.value] = argument
end

directives[directive_name] = util.map(directive.arguments or {}, function(argument, name)
local supplied = directiveArgumentMap[name] and directiveArgumentMap[name].value
local defaultValue = argument.defaultValue
if argument.kind then argument = argument.kind end
directivesDefaultValues[directive_name] = directivesDefaultValues[directive_name] or {}
if defaultValue ~= nil then directivesDefaultValues[directive_name][name] = defaultValue end
local res = util.coerceValue(supplied, argument, context.variables, {
strict_non_null = true,
defaultValues = defaultValues,
})

return res
end)
end
end)
end

local info = {
context = context,
Expand All @@ -298,6 +333,7 @@ local function getFieldEntry(objectType, object, fields, context)
operation = context.operation,
variableValues = context.variables,
defaultValues = context.defaultValues,
directives = directives,
}

local resolvedObject, err = (fieldType.resolve or defaultResolver)(object, arguments, info)
Expand All @@ -307,13 +343,12 @@ local function getFieldEntry(objectType, object, fields, context)

local subSelections = mergeSelectionSets(fields)
return completeValue(fieldType.kind, resolvedObject, subSelections, context,
{fieldName = fieldName}
{fieldName = fieldName,}
), err
end

evaluateSelections = function(objectType, object, selections, context)
local result = {}
local errors
local err
local fields = collectFields(objectType, selections, {}, {}, context)
for _, field in ipairs(fields) do
Expand All @@ -322,14 +357,14 @@ evaluateSelections = function(objectType, object, selections, context)
result[field.name], err = getFieldEntry(objectType, object, {field.selection},
context)
if err ~= nil then
errors = errors or {}
table.insert(errors, err)
context.errors = context.errors or {}
table.insert(context.errors, err)
end
if result[field.name] == nil then
result[field.name] = box.NULL
end
end
return result, errors
return result, context.errors
end

local function execute(schema, tree, rootValue, variables, operationName)
Expand All @@ -346,4 +381,4 @@ local function execute(schema, tree, rootValue, variables, operationName)
end


return {execute=execute}
return {execute=execute,}
Loading