LuaGraphQLClient
a minimal Lua module for crafting and performing basic GraphQL queries from Roblox
Install / Use
/learn @jakedowns/LuaGraphQLClientREADME
Roblox / Lua GraphQLClient
a minimal Lua module for crafting and performing basic GraphQL queries from Roblox
author: @VertPix on Roblox | @jakedowns on Twitter
Interactive Demo: Play with a live sample on REPL.it
About:
This helper consists of 3 modules:
- Queries: a table of query definitions keyed by name
- GraphQL: a module for defining a Query/Mutation with a method for converting it into a valid GraphQL query string
- API: a module for initializing a Query and firing the HTTP Post Async request
Usage:
- define Queries in the
Queries.luamodule
NOTE any Arrays (non-keyed / integer keyed tables) infunction queries.ExampleOperation(args) local gql = GraphQL.new({ mutation = true, op = "ExampleOperation" }) -- Example Operation Arguments local anArray = {__isArray=true,"red","orange","yellow"} local aDictionary = {foo="bar"} gql.baseArgs['colors'] = anArray gql.baseArgs['preferences'] = aDictionary gql.baseArgs["status"] = "great" -- Example Response Arguments table.insert(gql.responseArgs,"errors") -- [String] table.insert(gql.responseArgs,"successes") -- [String] gql.responseArgs["resultSet"] = { nestedArray = {"fieldA", "fieldB", "fieldC"} } gql.responseArgs["secondaryResultSet"] = { "fieldA", fieldB = { "property1", "property2" }, "fieldC" } return gql endrequestArgsshould be flagged with a__isArray=trueresponseArgsare automatically assumed arrays - execute a query by using the API and passing in a Query key name:
local API = require(script.Parent.API) local query = API.newRequest("ExampleOperation") local response = query.send() -- returns a JSON-decoded response - profit!!!
How it works
- the API wraps the call:
Note: the example API module uses Roblox HttpServicelocal gql = Queries[queryName](args) local payload = HttpService:JSONEncode({ --operationName = nil, query = gql.getQueryString(), --variables = {} });
Input
-- Instance of GraphQL.new({mutation:<bool>,op:<string>})
{
base = "ExampleOperation", -- todo: rename this to operation / operationName
mutation = true, -- a bool flag
getQueryString = <function 1>, -- the string builder fn
parts = {}, -- gets populated by string builder
-- todo rename this to operation or request arguments
baseArgs = {
colors = { "red", "orange", "yellow", __isArray = true},
preferences = {foo = "bar"},
status = "great"
},
responseArgs = {
"errors",
"successes",
primaryResultSet = {
nestedArray = { "fieldA", "fieldB", "fieldC" }
},
secondaryResultSet = {
"fieldA",
"fieldC"
fieldB = {
"property1",
"property2"
}
}
}
}
Output
-- todo don't need to output commas in array here (;
mutation {
ExampleOperation(
status: "great"
colors: ["red", "orange", "yellow"]
preferences: { foo: "bar" }
) {
errors
successes
secondaryResultSet {
fieldA
fieldC
fieldB {
property1
property2
}
}
primaryResultSet {
nestedArray {
fieldA
fieldB
fieldC
}
}
}
}
</details>
TODO:
- write tests
- error handling for malformed responses
- support for
operationNameandvariables - full OAUTH2 negotiation example
- make a generic non-roblox example
- remove commas from array output
- make response args __isArray by default
- make request args table by default, not nil
- maybe add a heuristic to determine if something is an array automagically
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
