hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.18k stars 2.77k forks source link

server: Fix the `path` value in the response of error reply of `replace_metadata` #7769

Closed codingkarthik closed 3 years ago

codingkarthik commented 3 years ago

Version Information

Server Version: CLI Version (for CLI related issue):

Environment

What is the expected behaviour?

Consider the following metadata:

{
    "type": "replace_metadata",
    "version": 2,
    "args": {
        "allow_inconsistent_metadata": true,
        "metadata": {
            "inherited_roles": [],
            "sources": [
                {
                    "configuration": {
                        "connection_info": {
                            "database_url": {
                                "from_env": "HASURA_GRAPHQL_DATABASE_URL"
                            },
                            "isolation_level": "read-committed",
                            "pool_settings": {
                                "connection_lifetime": 600,
                                "idle_timeout": 180,
                                "max_connections": 50,
                                "retries": 1
                            },
                            "use_prepared_statements": true
                        }
                    },
                    "kind": "postgres",
                    "name": "default",
                    "tables": [   

                    ]
                },
                {
                    "configuration": {
                        "connection_info": {
                            "database_url": "<REDACTED>",
                            "isolation_level": "read-committed",
                            "use_prepared_statements": false
                        }
                    },
                    "kind": "postgres",
                    "name": "db3",
                    "tables": [
                        {
                            "table": {
                                "name": "check",
                                "schema": "public"
                            }
                        },
                        {
                            "table": {
                                "names": "t1d",   <---------- `names` instead of `name`
                                "schema": "public"
                            }
                        },
                        {
                            "table": {
                                "name": "t2d",
                                "schema": "public"
                            }
                        }
                    ]
                }
            ],
            "version": 3
        }
    }
}

While trying to replace this metadata in the graphql-engine, we get the following response:

{
  "path": "$.args.metadata.tables[1].table",
  "error": "key \"name\" not found",
  "code": "parse-failed"
}

the path here is incorrect, as the correct JSON path is $.args.metadata.sources[0].tables[1].table object and the same should be returned in the response.

Keywords

What is the current behaviour?

How to reproduce the issue?

1. 2. 3.

Screenshots or Screencast

Please provide any traces or logs that could help here.

Any possible solutions?

Can you identify the location in the source code where the problem exists?

If the bug is confirmed, would you be willing to submit a PR?

ecthiender commented 3 years ago

Fixed via b3464c9cb2190ea700813fb539cac346d5ba7362