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

Commit 9981b77

Browse files
committed
Allow to pass compile opts over bunch of functions
1 parent d54f583 commit 9981b77

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

graphql/impl.lua

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ end
7272
---
7373
--- @treturn table result of the operation
7474
local function compile_and_execute(state, query, variables, operation_name,
75-
opts)
75+
compile_opts)
7676
assert(type(state) == 'table', 'use :compile_and_execute(...) ' ..
7777
'instead of .compile_and_execute(...)')
7878
assert(state.schema ~= nil, 'have not compiled schema')
7979
check(query, 'query', 'string')
8080
check(variables, 'variables', 'table', 'nil')
8181
check(operation_name, 'operation_name', 'string', 'nil')
82-
check(opts, 'opts', 'table', 'nil')
82+
check(compile_opts, 'compile_opts', 'table', 'nil')
8383

84-
local compiled_query = state:compile(query, opts)
84+
local compiled_query = state:compile(query, compile_opts)
8585
return compiled_query:execute(variables, operation_name)
8686
end
8787

@@ -135,14 +135,14 @@ local function gql_compile(state, query, opts)
135135
return gql_query
136136
end
137137

138-
local function start_server(gql, host, port)
138+
local function start_server(gql, host, port, compile_opts)
139139
assert(type(gql) == 'table',
140140
'use :start_server(...) instead of .start_server(...)')
141141

142142
check(host, 'host', 'nil', 'string')
143143
check(port, 'port', 'nil', 'number')
144144

145-
gql.server = server.init(gql, host, port)
145+
gql.server = server.init(gql, host, port, compile_opts)
146146
gql.server:start()
147147

148148
return ('The GraphQL server started at http://%s:%s'):format(
@@ -196,26 +196,27 @@ local function create_default_accessor(cfg)
196196
end
197197
end
198198

199-
function impl.compile(query)
199+
function impl.compile(query, opts)
200200
if default_instance == nil then
201201
default_instance = impl.new()
202202
end
203-
return default_instance:compile(query)
203+
return default_instance:compile(query, opts)
204204
end
205205

206-
function impl.execute(query, variables, operation_name)
206+
function impl.execute(query, variables, operation_name, compile_opts)
207207
if default_instance == nil then
208208
default_instance = impl.new()
209209
end
210-
return default_instance:execute(query, variables, operation_name)
210+
return default_instance:execute(query, variables, operation_name,
211+
compile_opts)
211212
end
212213

213-
function impl.start_server()
214+
function impl.start_server(host, port, compile_opts)
214215
if default_instance == nil then
215216
default_instance = impl.new()
216217
end
217218

218-
return default_instance:start_server()
219+
return default_instance:start_server(host, port, compile_opts)
219220
end
220221

221222
function impl.stop_server()

graphql/server/server.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ local function static_handler(req)
4343
}
4444
end
4545

46-
function server.init(graphql, host, port)
46+
function server.init(graphql, host, port, compile_opts)
4747
local host = host or '127.0.0.1'
4848
local port = port or 8080
4949
local httpd = require('http.server').new(host, port)
@@ -103,7 +103,7 @@ function server.init(graphql, host, port)
103103

104104
local traceback
105105
local ok, compiled_query = xpcall(function()
106-
return graphql:compile(query)
106+
return graphql:compile(query, compile_opts)
107107
end, function(err)
108108
traceback = debug.traceback()
109109
return err

0 commit comments

Comments
 (0)