
Publisher
jsingla
GraphQL client
A small library to do graphql request from gdscript without external dependencies
This plugin has been mirrored from the Godot Asset Library.
The plugin author is in no way affiliated with Gadget.
If you are the author of this plugin and would like this mirror removed, please contact support@gadgetgodot.com.
Godot GraphQLClient Addon
Prerequisits
You need to have GUT in your project. See https://gut.readthedocs.io/en/latest/Install.html
Instalation
- download the contents (or clone) and put inside $PROJECT/addons
- Create a class extending GQLClient
- Implement in a _ready function or in the same _init to configure it calling to set_endpoint(is_secure, host, port, path)
- Add this class as an autoload of your godot project.
Usage
This library uses his own objects to create the query. But provide also a raw argument to call with a string.
- create some graphql query:
var query =GQLQuery.new("someProp").set_args_v2({"arg":"variable"}).set_props([
"otherProp",
GQLQuery.new("moreComplexProp")
])
- Call to your singleton to the query method and add it to your node_tree:
var my_query_executer = ServerConfigInstance.query("NameOfTheQuery", {"variable":"HisType"}, query)
- Connect to graphql_response signal to retrieve the data
- Execute the run method with the variables as args
my_query_executor.run({"variable":42})
You can see the sample project
Features
- Tested with a django-graphene server
- Do queries and mutations
- gql_query tested using gut
Documentation
GQLQuery samples
The sample of use in the usage will generate something like this:
someProp(arg:$variable){
otherProp
moreComplexProp
}
As you can see there is no query information or mutation. The query or mutation is added when you call to client.query or client.mutation. The query generated in the point usage 4 is the following:
query NameOfTheQuery(variable: HisType){
someProp(arg:$variable){
otherProp
moreComplexProp
}
}
Adding the variable of variable to 42
Writing the graphql with samples
- Query a field with variables
var gqlClient : GqlClient = get_node('/root/GqlClient')
var subject = GQLQuery.new("prop").set_args_v2({"argument": "input"}).set_props(["sample"])
var executor = gqlClient.query("queryName", {"input": "String" }, subject)
Will generate
query queryName ($input: String) {
prop(argument: $input){
sample
}
}
- Using variable shortcut, when the argument name is the same as the variable, we can use a $ to automatically match them
var gqlClient : GqlClient = get_node('/root/GqlClient')
var subject = GQLQuery.new("prop").set_args_v2({"argument": "$"}).set_props(["sample"])
var executor = gqlClient.query("queryName", {"argument": "String" }, subject)
Will generate
query queryName ($argument: String) {
prop(argument: $argument){
sample
}
}