{
  "resource_version": 40,
  "metadata": {
    "version": 3,
    "sources": [
      {
        "name": "default",
        "kind": "postgres",
        "tables": [{% set classes = package.get_all_classes() %}{% for cls in classes %}{% if cls.is_abstract == False and cls.id_attribute %}
            { {% set objects = cls.get_object_relationships() %}{% set array_objects = cls.get_array_relationships() %}
                "table":{
                    "name": "{{ cls.package.name | snakecase }}__{{ cls.name | snakecase }}",
                    "schema": "public"
                }{% if objects|count > 0 %},
                "object_relationships": [{% for obj in objects %}
                    {
                        "name": "obj_{{ obj.package.name | snakecase }}__{{ obj.name | snakecase }}",
                        "using": {
                            "foreign_key_constraint_on": "{{ obj.id_attribute.name | snakecase }}"
                        }
                    }{% if loop.index != objects|count %},{% endif %}{% endfor %}
                ]{% endif %}{% if array_objects|count > 0 %},
                "array_relationships": [{% for obj in array_objects %}
                    {
                        "name": "list_{{ obj.package.name | snakecase }}__{{ obj.name | snakecase }}",
                        "using": {
                            "foreign_key_constraint_on": {
                                "column": "{{ obj.id_attribute.name | snakecase }}",
                                "table": {
                                    "name": "{{ obj.package.name | snakecase }}__{{ obj.name | snakecase }}",
                                    "schema": "public"
                                }
                            }
                        }
                    }{% if loop.index != array_objects|count %},{% endif %}{% endfor %}
                ]{% endif %}
            }{% if cls != classes[-1] %},{% endif %}{% endif %}{% endfor %}
        ],
        "configuration": {
          "connection_info": {
            "database_url": {
              "from_env": "HASURA_GRAPHQL_METADATA_DATABASE_URL"
            },
            "isolation_level": "read-committed",
            "use_prepared_statements": false
          }
        }
      }
    ],
    "allowlist": [
      {
        "collection": "allowed-queries",
        "scope": {
          "global": true
        }
      }
    ]    
  }
}

