1
0
mirror of https://github.com/hasura/graphql-engine.git synced 2024-12-15 17:31:56 +03:00
graphql-engine/scripts/data-sources-util.sh
Brandon Simmons 6e8da71ece server: migrate to aeson-2 in preparation for ghc 9.2 upgrade
(Work here originally done by awjchen, rebased and fixed up for merge by
jberryman)

This is part of a merge train towards GHC 9.2 compatibility. The main
issue is the use of the new abstract `KeyMap` in 2.0. See:
https://hackage.haskell.org/package/aeson-2.0.3.0/changelog

Alex's original work is here:


BEHAVIOR CHANGE NOTE: This change causes a different arbitrary ordering
of serialized Json, for example during metadata export. CLI users care
about this in particular, and so we need to call it out as a _behavior
change_ as we did in v2.5.0. The good news though is that after this
change ordering should be more stable (alphabetical key order).

See: https://hasurahq.slack.com/archives/C01M20G1YRW/p1654012632634389

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4611
Co-authored-by: awjchen <13142944+awjchen@users.noreply.github.com>
GitOrigin-RevId: 700265162c782739b2bb88300ee3cda3819b2e87
2022-06-08 15:32:27 +00:00

134 lines
4.3 KiB
Bash

#!/usr/bin/env bash
# functions common to dev.sh (local testing) and test-server.sh (CI tests)
function add_sources() {
hasura_graphql_server_port=${1:-8181}
# always add a Postgres source for metadata, at least
add_postgres_source "$hasura_graphql_server_port" "$PG_DB_URL"
case "$BACKEND" in
citus)
add_citus_source "$hasura_graphql_server_port" "$CITUS_DB_URL"
;;
mssql)
add_mssql_source "$hasura_graphql_server_port" "$MSSQL_CONN_STR"
;;
mysql)
add_mysql_source "$hasura_graphql_server_port"
;;
bigquery)
add_bigquery_source "$hasura_graphql_server_port"
;;
esac
echo ""
}
function add_postgres_source() {
hasura_graphql_server_port=${1}
db_url=${2}
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
echo ""
echo "Adding Postgres source"
# FIXME: Without a loop here `dev.sh test` fails for me here. With the loop
# I get “source with name \"default\" already exists”
until curl -s "$metadata_url" \
--data-raw '{"type":"pg_add_source","args":{"name":"default","configuration":{"connection_info":{"database_url":"'"$db_url"'"}}}}'; &>/dev/null; do
echo -n '.' && sleep 0.2
done
echo " Ok"
}
function add_citus_source() {
hasura_graphql_server_port=${1}
db_url=${2}
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
echo ""
echo "Adding Citus source"
curl --fail "$metadata_url" \
--data-raw '{"type":"citus_add_source","args":{"name":"citus","configuration":{"connection_info":{"database_url":"'"$db_url"'"}}}}'
}
function add_mssql_source() {
hasura_graphql_server_port=${1}
connection_string=${2}
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
echo ""
echo "Adding SQL Server source"
curl --fail "$metadata_url" \
--data-raw '{"type":"mssql_add_source","args":{"name":"mssql","configuration":{"connection_info":{"connection_string":"'"$connection_string"'"}}}}'
}
function add_mysql_source() {
hasura_graphql_server_port=${1}
# connection_string currently unused as mysql_add_source not yet supported
# connection_string=${2}
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
echo ""
echo "Adding MySQL source"
curl --fail "$metadata_url" \
--data-raw '{"type":"replace_metadata","args":{"version":3,"sources":[{"name":"mysql","kind":"mysql","tables":[],"configuration":{"database":"hasura","user":"'"$MYSQL_USER"'","password":"'"$MYSQL_PASSWORD"'","host":"127.0.0.1","port":'"$MYSQL_PORT"',"pool_settings":{}}}]}}'
}
function add_bigquery_source() {
hasura_graphql_server_port=${1}
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
echo ""
echo "Adding BigQuery sources to project $HASURA_BIGQUERY_PROJECT_ID"
curl --fail "$metadata_url" \
--data-raw '
{
"type": "replace_metadata",
"args": {
"metadata": {
"version": 3,
"sources": [
{
"name": "bigquery",
"kind": "bigquery",
"tables": [],
"configuration": {
"service_account": {
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
},
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
"datasets": ["hasura"]
}
},
{
"name": "bigquery2",
"kind": "bigquery",
"tables": [],
"configuration": {
"service_account": {
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
},
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
"datasets": ["hasura"]
}
},
{
"name": "hasura_global_limited",
"kind": "bigquery",
"tables": [],
"configuration": {
"global_select_limit": 1,
"service_account": {
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
},
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
"datasets": ["hasura"]
}
}
]
}
}
}
'
}