#!/usr/bin/env bash # Usage: bash add-event.sh # The JSON file should match the Event schema (see CLAUDE.md). # id, createdAt, updatedAt, _version, _deleted, _lastChangedAt are auto-managed. set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" [ -f "$REPO_ROOT/.env" ] && set -a && source "$REPO_ROOT/.env" && set +a ENDPOINT="https://APP_SYNC_ENDPOINT_REDACTED/graphql" API_KEY="${APP_SYNC_API_KEY:-APP_SYNC_API_KEY_REDACTED}" JSON_FILE="${1:-}" if [ -z "$JSON_FILE" ]; then echo "Usage: $0 " exit 1 fi INPUT=$(python3 -c " import json, sys with open('$JSON_FILE') as f: data = json.load(f) # Remove read-only / auto-managed fields for k in ['id', 'createdAt', 'updatedAt', '_version', '_deleted', '_lastChangedAt', '_note']: data.pop(k, None) # Remove null fields (optional) data = {k: v for k, v in data.items() if v is not None} print(json.dumps(data)) ") QUERY='mutation CreateEvent($input: CreateEventInput!) { createEvent(input: $input) { id type date title venueName published } }' PAYLOAD=$(python3 -c " import json, sys q = '$QUERY' inp = $INPUT print(json.dumps({'query': q, 'variables': {'input': inp}})) ") echo "Creating event from $JSON_FILE ..." RESULT=$(curl -s -X POST "$ENDPOINT" \ -H "Content-Type: application/json" \ -H "x-api-key: $API_KEY" \ -d "$PAYLOAD") echo "$RESULT" | python3 -m json.tool echo "" echo "Done. Run 'bash deploy.sh' to rebuild the site."