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

Commit 7092b67

Browse files
committed
Allow to pass compile opts over bunch of functions
1 parent 57bdff5 commit 7092b67

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
@@ -105,16 +105,16 @@ end
105105
---
106106
--- @treturn table result of the operation
107107
local function compile_and_execute(state, query, variables, operation_name,
108-
opts)
108+
compile_opts)
109109
assert(type(state) == 'table', 'use :compile_and_execute(...) ' ..
110110
'instead of .compile_and_execute(...)')
111111
assert(state.schema ~= nil, 'have not compiled schema')
112112
check(query, 'query', 'string')
113113
check(variables, 'variables', 'table', 'nil')
114114
check(operation_name, 'operation_name', 'string', 'nil')
115-
check(opts, 'opts', 'table', 'nil')
115+
check(compile_opts, 'compile_opts', 'table', 'nil')
116116

117-
local compiled_query = state:compile(query, opts)
117+
local compiled_query = state:compile(query, compile_opts)
118118
return compiled_query:execute(variables, operation_name)
119119
end
120120

@@ -170,14 +170,14 @@ local function gql_compile(state, query, opts)
170170
return gql_query
171171
end
172172

173-
local function start_server(gql, host, port)
173+
local function start_server(gql, host, port, compile_opts)
174174
assert(type(gql) == 'table',
175175
'use :start_server(...) instead of .start_server(...)')
176176

177177
check(host, 'host', 'nil', 'string')
178178
check(port, 'port', 'nil', 'number')
179179

180-
gql.server = server.init(gql, host, port)
180+
gql.server = server.init(gql, host, port, compile_opts)
181181
gql.server:start()
182182

183183
return ('The GraphQL server started at http://%s:%s'):format(
@@ -231,26 +231,27 @@ local function create_default_accessor(cfg)
231231
end
232232
end
233233

234-
function impl.compile(query)
234+
function impl.compile(query, opts)
235235
if default_instance == nil then
236236
default_instance = impl.new()
237237
end
238-
return default_instance:compile(query)
238+
return default_instance:compile(query, opts)
239239
end
240240

241-
function impl.execute(query, variables, operation_name)
241+
function impl.execute(query, variables, operation_name, compile_opts)
242242
if default_instance == nil then
243243
default_instance = impl.new()
244244
end
245-
return default_instance:execute(query, variables, operation_name)
245+
return default_instance:execute(query, variables, operation_name,
246+
compile_opts)
246247
end
247248

248-
function impl.start_server()
249+
function impl.start_server(host, port, compile_opts)
249250
if default_instance == nil then
250251
default_instance = impl.new()
251252
end
252253

253-
return default_instance:start_server()
254+
return default_instance:start_server(host, port, compile_opts)
254255
end
255256

256257
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)