GraphQl 0.123 - Dynamic columns + re-adding old Device table columns

This commit is contained in:
jokob-sk
2024-11-14 16:50:23 +11:00
parent 072821181a
commit c1c6813b6e
7 changed files with 235 additions and 85 deletions

View File

@@ -12,7 +12,8 @@ INSTALL_PATH="/app"
sys.path.extend([f"{INSTALL_PATH}/server"])
from logger import mylog
from helper import get_setting_value
from helper import get_setting_value, timeNowTZ
from notification import write_notification
app = Flask(__name__)
@@ -24,22 +25,23 @@ def graphql_endpoint():
# Check for API token in headers
token = request.headers.get("Authorization")
if token != f"Bearer {API_TOKEN}":
mylog('none', [f'[graphql_server] Unauthorized access attempt'])
mylog('verbose', [f'[graphql_server] Unauthorized access attempt'])
return jsonify({"error": "Unauthorized"}), 401
data = request.get_json()
mylog('none', [f'[graphql_server] data: {data}'])
mylog('verbose', [f'[graphql_server] data: {data}'])
# Use the schema to execute the GraphQL query
result = devicesSchema.execute(data.get("query"), variables=data.get("variables"))
mylog('none', [f'[graphql_server] result: {result}'])
# Return the data from the query in JSON format
return jsonify(result.data)
def start_server():
"""Function to start the GraphQL server in a background thread."""
mylog('none', [f'[graphql_server] Starting on port "{GRAPHQL_PORT}"'])
mylog('verbose', [f'[graphql_server] Starting on port: {GRAPHQL_PORT}'])
# Start the Flask app in a separate thread
thread = threading.Thread(target=lambda: app.run(host="0.0.0.0", port=GRAPHQL_PORT, debug=True, use_reloader=False))