graphql-engine/server
Jesse Hallett 84fd5910b0 server: polymorphic codec for metadata sources
This PR expands the OpenAPI specification generated for metadata to include separate definitions for `SourceMetadata` for each native database type, and for DataConnector.

For the most part the changes add `HasCodec` implementations, and don't modify existing code otherwise.

The generated OpenAPI spec can be used to generate TypeScript definitions that distinguish different source metadata types based on the value of the `kind` properly. There is a problem: because the specified `kind` value for a data connector source is any string, when TypeScript gets a source with a `kind` value of, say, `"postgres"`, it cannot unambiguously determine whether the source is postgres, or a data connector. For example,

```ts
function consumeSourceMetadata(source: SourceMetadata) {
    if (source.kind === "postgres" || source.kind === "pg") {
        // At this point TypeScript infers that `source` is either an instance
        // of `PostgresSourceMetadata`, or `DataconnectorSourceMetadata`. It
        // can't narrow further.
        source
    }
    if (source.kind === "something else") {
        // TypeScript infers that this `source` must be an instance of
        // `DataconnectorSourceMetadata` because `source.kind` does not match
        // any of the other options.
        source
    }
}
```

The simplest way I can think of to fix this would be to add a boolean property to the `SourceMetadata` type along the lines of `isNative` or `isDataConnector`. This could be a field that only exists in serialized data, like the metadata version field. The combination of one of the native database names for `kind`, and a true value for `isNative` would be enough for TypeScript to unambiguously distinguish the source kinds.

But note that in the current state TypeScript is able to reference the short `"pg"` name correctly!

~~Tests are not passing yet due to some discrepancies in DTO serialization vs existing Metadata serialization. I'm working on that.~~

The placeholders that I used for table and function metadata are not compatible with the ordered JSON serialization in use. I think the best solution is to write compatible codecs for those types in another PR. For now I have disabled some DTO tests for this PR.

Here are the generated [OpenAPI spec](https://github.com/hasura/graphql-engine-mono/files/9397333/openapi.tar.gz) based on these changes, and the generated [TypeScript client code](https://github.com/hasura/graphql-engine-mono/files/9397339/client-typescript.tar.gz) based on that spec.

Ticket: [MM-66](https://hasurahq.atlassian.net/browse/MM-66)

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5582
GitOrigin-RevId: e1446191c6c832879db04f129daa397a3be03f62
2022-08-25 18:36:02 +00:00
..
bench-wrk server/tests-py: Reduce the number of locations we check the status code. 2022-07-05 18:01:07 +00:00
benchmarks benchmarks: Add Accept-Encoding: gzip headers (NO REGRESSION) 2022-08-25 06:43:18 +00:00
documentation server/postgres: test identifier uniqueness rewrite 2022-06-17 10:44:18 +00:00
lib server: Move the schema parsers to their own library. 2022-08-05 13:53:39 +00:00
src-dc-api Adds support for GDC relationships in metadata API and adds support for foreign key constraints to GDC 2022-08-23 21:47:26 +00:00
src-emit-metadata-openapi server: initial set of DTO types for metadata 2022-06-27 16:33:31 +00:00
src-exec server: accept extensions_schema while adding a source 2022-08-10 09:42:09 +00:00
src-lib server: polymorphic codec for metadata sources 2022-08-25 18:36:02 +00:00
src-rsr fix cockroach_table_metadata.sql syntax error 2022-08-22 14:18:46 +00:00
src-test server: polymorphic codec for metadata sources 2022-08-25 18:36:02 +00:00
tests-dc-api server: Data Connectors support for ordering by related table column and aggregates [GDW-126] 2022-08-19 07:01:52 +00:00
tests-hspec add cockroach to docker compose and tests-hspec 2022-08-25 17:18:40 +00:00
tests-py server/tests-py: Fix some warnings. 2022-08-24 08:32:07 +00:00
.dockerignore update packages (#251) 2018-08-08 13:10:13 +05:30
.gitignore server: Clean up Cabal project files 2022-04-07 07:16:12 +00:00
commit_diff.txt Rewrite GraphQL schema generation and query parsing (close #2801) (#4111) 2020-08-21 12:27:01 -05:00
COMPILING-ON-MACOS.md tooling: Opt-in shared tooling 2022-06-16 17:12:35 +00:00
CONTRIBUTING.md Use docker compose, not docker-compose. 2022-08-02 10:30:57 +00:00
graphql-engine.cabal server: polymorphic codec for metadata sources 2022-08-25 18:36:02 +00:00
Makefile ci: misc. cleanup, naming 2022-01-03 06:26:39 +00:00
STYLE.md Nix: Use nixpkgs-fmt to format everything. 2022-06-20 13:02:45 +00:00
testing-guidelines.md server: testing guidelines 2022-03-08 09:53:27 +00:00
troubleshooting.md Create troubleshooting.md 2022-05-30 09:18:44 +00:00
VERSIONS.json server: Automate generation and verification of Cabal files from hpack. 2022-07-29 16:22:12 +00:00