From c85692ab9e2d179292ab331e8b5211718fde1d06 Mon Sep 17 00:00:00 2001 From: William Luke Date: Mon, 1 Nov 2021 10:48:05 +0300 Subject: [PATCH] graphql server --- .envrc | 6 +- apps/cic-eth/cic_eth/graphql/app.py | 24 +++++++ apps/cic-eth/cic_eth/graphql/helpers.py | 87 +++++++++++++++++++++++++ apps/cic-eth/cic_eth/graphql/schema.py | 78 ---------------------- apps/cic-eth/requirements.txt | 4 +- docker-compose.yml | 4 +- 6 files changed, 121 insertions(+), 82 deletions(-) create mode 100644 apps/cic-eth/cic_eth/graphql/app.py create mode 100644 apps/cic-eth/cic_eth/graphql/helpers.py diff --git a/.envrc b/.envrc index 6ad52af5..9daa87cb 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,6 @@ export COMPOSE_DOCKER_CLI_BUILD=1 -export DOCKER_BUILDKIT=1 \ No newline at end of file +export DOCKER_BUILDKIT=1 +export FAUCET_AMOUNT=100000000000 +export TOKEN_TYPE=giftable_erc20_token +export TOKEN_NAME=Coffee +export TOKEN_SYMBOL=COFE \ No newline at end of file diff --git a/apps/cic-eth/cic_eth/graphql/app.py b/apps/cic-eth/cic_eth/graphql/app.py new file mode 100644 index 00000000..d669df77 --- /dev/null +++ b/apps/cic-eth/cic_eth/graphql/app.py @@ -0,0 +1,24 @@ +from cic_eth.graphql.schema import schema +from flask import Flask +from flask_graphql import GraphQLView + + +def create_app(): + app = Flask(__name__) + app.add_url_rule( + '/graphql', + view_func=GraphQLView.as_view( + 'graphql', + schema=schema, + graphiql=True + ) + ) + @app.route("/") + def test(): + return "Test ok!" + + return app + +if __name__ == "__main__": + app = create_app() + app.run(host='0.0.0.0', port=5000) diff --git a/apps/cic-eth/cic_eth/graphql/helpers.py b/apps/cic-eth/cic_eth/graphql/helpers.py new file mode 100644 index 00000000..f35f9513 --- /dev/null +++ b/apps/cic-eth/cic_eth/graphql/helpers.py @@ -0,0 +1,87 @@ + +query_with_argument = """ +{ + defaultToken{ + symbol + } +} + +""" +# result = schema.execute(query_with_argument) +# print(result) + + +mutation_with_argument = """ +mutation { + createAccount(password:"test"){ + address + } +} + +""" +m_result = schema.execute(mutation_with_argument) +print(m_result) +mutation_with_argument = """ +mutation { + createAccount(password:"test"){ + address + } +} + +""" +m_result = schema.execute(mutation_with_argument) +print(m_result) + +balance_query = """ +query { + balance(address:"0xcf41bd087b71c72d748fe2b8b4c88b2367c37df3", tokenSymbols:["GFT", "COFE"]){ + balanceNetwork + balanceIncoming + balanceOutgoing + balanceAvailable + } +} + +""" +# balance_query_result = schema.execute(balance_query) +# print(balance_query_result) + + +transfer_mutation = """ +mutation { + transfer(fromAddress :"0xcf41bd087b71c72d748fe2b8b4c88b2367c37df3", +toAddress: "0x63474da1a315f9abe0999b6adb61ae8a9ea19a76" +value: 20 +tokenSymbol: "COFE" ){ + test + } +} + +""" +transfer_mutation_result = schema.execute(transfer_mutation) +print(transfer_mutation_result) + + +balance_query = """ +query { + balance(address:"0x63474da1a315f9abe0999b6adb61ae8a9ea19a76", tokenSymbols:["GFT"]){ + balanceNetwork + balanceIncoming + balanceOutgoing + balanceAvailable + } +} + +""" +# balance_query_result = schema.execute(balance_query) +# print(balance_query_result) + + +transactions_query = """ +query { + transactions(address:"0xcf41bd087b71c72d748fe2b8b4c88b2367c37df3") +} + +""" +# transactions_query_result = schema.execute(transactions_query) +# print(transactions_query_result) diff --git a/apps/cic-eth/cic_eth/graphql/schema.py b/apps/cic-eth/cic_eth/graphql/schema.py index 6ef70270..cec83593 100644 --- a/apps/cic-eth/cic_eth/graphql/schema.py +++ b/apps/cic-eth/cic_eth/graphql/schema.py @@ -186,81 +186,3 @@ class MyMutations(ObjectType): schema = Schema(query=Query, mutation=MyMutations) - -query_with_argument = """ -{ - defaultToken{ - symbol - } -} - -""" -# result = schema.execute(query_with_argument) -# print(result) - - -mutation_with_argument = """ -mutation { - createAccount(password:"test"){ - address - } -} - -""" -# m_result = schema.execute(mutation_with_argument) -# print(m_result) - - -balance_query = """ -query { - balance(address:"0x82e66cf2766bf20672a605bbf5a6faaa12d5b907", tokenSymbols:["GFT"]){ - balanceNetwork - balanceIncoming - balanceOutgoing - balanceAvailable - } -} - -""" -# balance_query_result = schema.execute(balance_query) -# print(balance_query_result) - - -transfer_mutation = """ -mutation { - transfer(fromAddress :"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C", -toAddress: "0x82e66cf2766bf20672a605bbf5a6faaa12d5b907" -value: 20 -tokenSymbol: "GFT" ){ - - } -} - -""" -transfer_mutation_result = schema.execute(transfer_mutation) -print(transfer_mutation_result) - - -balance_query = """ -query { - balance(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C", tokenSymbols:["GFT"]){ - balanceNetwork - balanceIncoming - balanceOutgoing - balanceAvailable - } -} - -""" -# balance_query_result = schema.execute(balance_query) -# print(balance_query_result) - - -transactions_query = """ -query { - transactions(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C") -} - -""" -# transactions_query_result = schema.execute(transactions_query) -# print(transactions_query_result) diff --git a/apps/cic-eth/requirements.txt b/apps/cic-eth/requirements.txt index 74239a6c..e3a6ab5e 100644 --- a/apps/cic-eth/requirements.txt +++ b/apps/cic-eth/requirements.txt @@ -3,4 +3,6 @@ chainlib-eth>=0.0.10a4,<0.1.0 semver==2.13.0 crypto-dev-signer>=0.4.15rc2,<0.5.0 uwsgi==2.0.19.1 -graphene>=2.0 \ No newline at end of file +graphene>=2.0 +flask>=2.0.2 +Flask-GraphQL>=2.0.1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 92141f12..409562da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -142,7 +142,7 @@ services: TASKS_TRACE_QUEUE_STATUS: ${TASKS_TRACE_QUEUE_STATUS:-1} restart: unless-stopped ports: - - 8080:8000 + - 5000:5000 depends_on: - evm - postgres @@ -158,7 +158,7 @@ services: set -a if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi set +a - ./start_tasker.sh --aux-all -q cic-eth -vv + ./start_tasker.sh --aux-all -q cic-eth -vv & python /root/cic_eth/graphql/app.py cic-eth-tracker: image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}