Skip to content

Conversation

@soupi
Copy link
Contributor

@soupi soupi commented Apr 5, 2024

What

Support ndc-spec v0.1.2.
This includes changing the type representations of some types.

How

The type representation has changed. We try to keep this change backwards compatible by mapping deprecated variants (Number, Integer) to new variants, and update types to more specific reps that didn't exist before.

We also have a problem with representing int8 now. ndc-spec v0.1.2 defines Int64 to be represented as a json string, which is not what we do. So we either have to lie (say it's an Int32 when it isn't) or break compatibility and cast int8 to string.
In this PR I did the former, and I'll introduce the latter change next.

Comment on lines 622 to 623
metadata::TypeRepresentation::Integer => models::TypeRepresentation::Int32,
metadata::TypeRepresentation::Number => models::TypeRepresentation::Float64,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop gap until we remove these.

@soupi soupi marked this pull request as ready for review April 5, 2024 13:46
@soupi soupi requested a review from plcplc April 5, 2024 13:46
SamirTalwar
SamirTalwar previously approved these changes Apr 7, 2024
@SamirTalwar
Copy link
Contributor

Dismissing my review because I just realized that the ndc-sdk commit points to a branch. Let's wait until that's merged and update the commit.

@SamirTalwar SamirTalwar dismissed their stale review April 7, 2024 21:19

The ndc-sdk commit points to a branch.

@soupi soupi marked this pull request as draft April 8, 2024 07:07
@soupi soupi marked this pull request as ready for review April 8, 2024 09:54
}

/// Map our local type representation to ndc-spec type representation.
fn map_type_representation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be changing the outputted type representations like this without the user providing us an opt-in config flag to do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is just translating our own TypeRepresentation type to ndc-spec TypeRepresentation type. Could you please elaborate on what do you mean? I'm not sure I understand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that our types should return the same ndc-spec TypeRepresentation as they did already before this change. Where this is not possible, because of removed types, we should return the more general json. Otherwise we're potentially changing behaviour without the user opting into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the type representations themselves to what they are supposed to be is not a breaking change, and the previous values (Integer, Number) are deprecated.

What's breaking is if we decide to say that bigints have the representation Int64, because:

  1. If we provide values for bigints as we currently do, as numbers, it would be against the spec
  2. If we change the runtime behavior and cast bigints to strings, we will return different results than we do now.

What we do here is to map each type (we know) to its right type representation, except bigints, which we map to json, and this is done in the version3/mod.rs code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will a version of engine that does not know about these types do when it receives them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ndc-schema concept that can be used by cli/lsp to generate engine objects, so I don't think this will be used directly in the engine. The engine already uses v0.1.2 of ndc-spec though: https://github.com/hasura/v3-engine/pull/443/files#diff-5e05c14aa4760c15d75bc66970581abe17a82eef4770a0cd9861bd40ce65934bR27

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh OK, makes sense. This all seems sensible then, thank you for indulging my questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gladly :)

// This is not what we do now and is a breaking change.
// This will need to be changed in the future. In the meantime, we report
// The type representation to be json.
database::TypeRepresentation::Json,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"float8": "float64",
"int2": "int16",
"int4": "int32",
"int8": "json",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the changes to the configuration. Number and String are deprecated in ndc-spec. We will still accept these for backwards compatibility reasons, but we will output the new representations. @danieljharvey

"even_number": {
"representation": {
"type": "integer"
"type": "int32"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the changes to the ndc schema.

@soupi soupi added this pull request to the merge queue Apr 8, 2024
Merged via the queue into main with commit 8df830b Apr 8, 2024
@soupi soupi deleted the gil/spec-0.1.2 branch April 8, 2024 13:17
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", rev = "7b56fac3aba2bc6533d3163111377fd5fbeb3011" }
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.1" }
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.2" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", rev = "7409334" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use the full SHA here because Cargo thinks two dependencies pointing to the same revision but using a different prefix length are actually different dependencies. This causes serious issues when using ndc-postgres as a dependency as it brings in ndc-sdk with the short ref, so everything else needs to use the exact same prefix length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Will fix.

@soupi soupi mentioned this pull request Apr 9, 2024
github-merge-queue bot pushed a commit that referenced this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants