Skip to content
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

GQL Client raw query가 아닌 class 제대로 사용하도록 수정 #182

Merged
merged 1 commit into from
May 20, 2024
Merged
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
181 changes: 73 additions & 108 deletions frontend/Savor-22b/gql/query.gd
Atralupus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,112 +1,77 @@
var get_villages_query = "query {
villages {
id
name
width
height
worldX
worldY
}
}"

var place_house_query_format = "query {
createAction_PlaceUserHouse(
publicKey: {},
villageId: {},
x: {},
y: {}
)
}"

var stage_tx_query_format = "mutation {
stageTransaction(
unsignedTransaction:\"%s\",
signature:\"%s\")
}"

var plant_seed_query_format = "query {
createAction_PlantingSeed(
publicKey: {},
fieldIndex: {},
itemStateIdToUse: {}
)
}"


var harvest_seed_query_format = "query {
createAction_HarvestingSeed(
publicKey: {},
fieldIndex: {}
)
}"


var remove_seed_query_format = "query {
createAction_RemovePlantedSeed(
publicKey: {},
fieldIndex: {}
)
}"

var remove_weed_query_format = "query {
createAction_RemoveWeed(
publicKey: {},
fieldIndex: {}
)
}"



var buy_shop_item_query_format = "query {
createAction_BuyShopItem(
publicKey: {},
desiredShopItemID: {}
)
}"

var buy_kitchen_equipment_query_format = "query {
createAction_BuyKitchenEquipment(
publicKey: {},
desiredEquipmentID: {}
)
}"

var install_kitchen_equipment_query_format = "query {
createAction_InstallKitchenEquipmentAction(
publicKey: {},
kitchenEquipmentStateID: {},
spaceNumber: {}
)
}"

var create_food_query_format = "query {
createAction_CreateFood(
publicKey: {},
recipeID: {},
refrigeratorStateIdsToUse: {},
kitchenEquipmentStateIdsToUse: {}
)
}"

var uninstall_kitchen_equipment_query_format = "query {
createAction_UninstallKitchenEquipmentActionQuery(
publicKey: {},
spaceNumber: {},
)
}"

var calculate_relocation_cost_query_template = GQLQuery.new("calculateRelocationCost").set_args({
var stage_tx_mutation = GQLQuery.new("stageTransaction").set_args({
"unsignedTransaction": "unsignedTransaction",
"signature": "signature",
});

var get_villages_query = GQLQuery.new("villages").set_props([
"id",
"name",
"width",
"height",
"worldX",
"worldY"
]);

var calculate_relocation_cost_query = GQLQuery.new("calculateRelocationCost").set_args({
"villageId": "villageId",
"relocationVillageId": "relocationVillageId",
"relocationVillageId": "relocationVillageId"
}).set_props([
"durationBlocks",
"price",
])
"price"
]);

var calculate_relocation_cost_query = SvrGqlClient.query(
'CalculateRelocationCost',
{
"villageId": "Int!",
"relocationVillageId": "Int!",
},
calculate_relocation_cost_query_template)
var place_house_query = GQLQuery.new("createAction_PlaceUserHouse").set_args({
"publicKey": "publicKey",
"villageId": "villageId",
"x": "x",
"y": "y"
});

var plant_seed_query = GQLQuery.new("createAction_PlantingSeed").set_args({
"publicKey": "publicKey",
"fieldIndex": "fieldIndex",
"itemStateIdToUse": "itemStateIdToUse"
});

var harvest_seed_query = GQLQuery.new("createAction_HarvestingSeed").set_args({
"publicKey": "publicKey",
"fieldIndex": "fieldIndex"
});

var remove_seed_query = GQLQuery.new("createAction_RemovePlantedSeed").set_args({
"publicKey": "publicKey",
"fieldIndex": "fieldIndex"
});

var remove_weed_query = GQLQuery.new("createAction_RemoveWeed").set_args({
"publicKey": "publicKey",
"fieldIndex": "fieldIndex"
});

var buy_shop_item_query = GQLQuery.new("createAction_BuyShopItem").set_args({
"publicKey": "publicKey",
"desiredShopItemID": "desiredShopItemID"
});

var buy_kitchen_equipment_query = GQLQuery.new("createAction_BuyKitchenEquipment").set_args({
"publicKey": "publicKey",
"desiredEquipmentID": "desiredEquipmentID"
});

var install_kitchen_equipment_query = GQLQuery.new("createAction_InstallKitchenEquipmentAction").set_args({
"publicKey": "publicKey",
"kitchenEquipmentStateID": "kitchenEquipmentStateID",
"spaceNumber": "spaceNumber"
});

var create_food_query = GQLQuery.new("createAction_CreateFood").set_args({
"publicKey": "publicKey",
"recipeID": "recipeID",
"refrigeratorStateIdsToUse": "refrigeratorStateIdsToUse",
"kitchenEquipmentStateIdsToUse": "kitchenEquipmentStateIdsToUse"
});

var uninstall_kitchen_equipment_query = GQLQuery.new("createAction_UninstallKitchenEquipmentActionQuery").set_args({
"publicKey": "publicKey",
"spaceNumber": "spaceNumber"
});
138 changes: 138 additions & 0 deletions frontend/Savor-22b/gql/query_executor.gd
Atralupus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
extends Node

class_name QueryExecutor

const GqlQuery = preload("res://gql/query.gd");
var gql_query = GqlQuery.new();

var stage_tx_mutation_executor = SvrGqlClient.mutation(
'StageTransaction',
{
"unsignedTransaction": "String!",
"signature": "String!"
},
gql_query.stage_tx_mutation
);

var calculate_relocation_cost_query_executor = SvrGqlClient.query(
'CalculateRelocationCost',
{
"villageId": "Int!",
"relocationVillageId": "Int!"
},
gql_query.calculate_relocation_cost_query
);

var get_villages_query_executor = SvrGqlClient.query(
'GetVillages',
{},
gql_query.get_villages_query
);

var place_house_query_executor = SvrGqlClient.query(
'PlaceHouse',
{
"publicKey": "String!",
"villageId": "Int!",
"x": "Int!",
"y": "Int!"
},
gql_query.place_house_query
);

var plant_seed_query_executor = SvrGqlClient.query(
'PlantSeed',
{
"publicKey": "String!",
"fieldIndex": "Int!",
"itemStateIdToUse": "Int!"
},
gql_query.plant_seed_query
);

var harvest_seed_query_executor = SvrGqlClient.query(
'HarvestSeed',
{
"publicKey": "String!",
"fieldIndex": "Int!"
},
gql_query.harvest_seed_query
);

var remove_seed_query_executor = SvrGqlClient.query(
'RemoveSeed',
{
"publicKey": "String!",
"fieldIndex": "Int!"
},
gql_query.remove_seed_query
);

var remove_weed_query_executor = SvrGqlClient.query(
'RemoveWeed',
{
"publicKey": "String!",
"fieldIndex": "Int!"
},
gql_query.remove_weed_query
);

var buy_shop_item_query_executor = SvrGqlClient.query(
'BuyShopItem',
{
"publicKey": "String!",
"desiredShopItemID": "Int!"
},
gql_query.buy_shop_item_query
);

var buy_kitchen_equipment_query_executor = SvrGqlClient.query(
'BuyKitchenEquipment',
{
"publicKey": "String!",
"desiredEquipmentID": "Int!"
},
gql_query.buy_kitchen_equipment_query
);

var install_kitchen_equipment_query_executor = SvrGqlClient.query(
'InstallKitchenEquipment',
{
"publicKey": "String!",
"kitchenEquipmentStateID": "Int!",
"spaceNumber": "Int!"
},
gql_query.install_kitchen_equipment_query
);

var create_food_query_executor = SvrGqlClient.query(
'CreateFood',
{
"publicKey": "String!",
"recipeID": "Int!",
"refrigeratorStateIdsToUse": "Int!",
"kitchenEquipmentStateIdsToUse": "Int!"
},
gql_query.create_food_query
);

var uninstall_kitchen_equipment_query_executor = SvrGqlClient.query(
'UninstallKitchenEquipment',
{
"publicKey": "String!",
"spaceNumber": "Int!"
},
gql_query.uninstall_kitchen_equipment_query
);

func stage_action(params, query_executor, mutation_executor):
query_executor.graphql_response.connect(
func(data):
var unsigned_tx = data["data"][data["data"].keys()[0]]
var signature = GlobalSigner.sign(unsigned_tx)
mutation_executor.run({
"unsignedTransaction": unsigned_tx,
"signature": signature
})
)
query_executor.run(params)
Loading
Loading