graphql-engine/server/src-lib/Data
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
..
Aeson Moving kriti function references into a single module for coordination of availability 2022-07-21 07:07:29 +00:00
HashMap/Strict server: polymorphic codec for metadata sources 2022-08-25 18:36:02 +00:00
List Weeding (2/?) 2022-06-09 16:40:49 +00:00
Parser server/parsers: Reduce usages of "utils"-like functions. 2022-07-06 07:56:35 +00:00
Text server: polymorphic codec for metadata sources 2022-08-25 18:36:02 +00:00
Time/Clock server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
URL Weeding (2/?) 2022-06-09 16:40:49 +00:00
Environment.hs Allows for mock env vars in test-webhook-transform endpoint 2021-12-09 07:59:46 +00:00
SerializableBlob.hs server: Refactor TByteString to SerializableBlob 2022-06-17 09:57:38 +00:00
SqlCommenter.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Trie.hs Extract generic containers from the codebase 2022-03-01 16:04:22 +00:00