-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse parameter type annotations when generating native query configuration #128
parse parameter type annotations when generating native query configuration #128
Conversation
1ceb7f9
to
aacb803
Compare
@@ -114,7 +117,8 @@ fn unable_to_infer_types_message( | |||
for name in problem_parameter_types { | |||
message += &format!("- {name}\n"); | |||
} | |||
message += "\nTry adding type annotations of the form: {{parameter_name|[int!]!}}\n"; | |||
message += "\nTry adding type annotations of the form: {{ parameter_name | [int!]! }}\n"; | |||
message += "\nIf you added an annotation, and you are still seeing this error then the type you gave may not be compatible with the context where the parameter is used.\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we link to somewhere they can read on supported types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to do a docs pass on the whole native query DX feature, then I'll have something to link to
}, | ||
|
||
// TODO: We probably want a separate step that swaps ElementOf and FieldOf constraints with | ||
// constraint of the targeted structure. We might do a similar thing with | ||
// WithFieldOverrides. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up tickets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the TODO because I don't think we need to worry about this
Ok(()) | ||
} | ||
|
||
// TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsupported right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - I wrote the test to see if it works, and it doesn't. I want to fix that later so I want to keep the test, but I don't want to commit a failing test.
aacb803
to
30bdfa8
Compare
This is work an an in-progress feature that is gated behind a feature flag,
native-query-subcommand
.Parses type annotations in placeholders that reference native query parameters. We already have an error message suggesting doing this, now the system actually reads these. For example,
The generated query for that configuration includes a parameter named
min_rating
with typeint
. Without the annotation it would have inferreddouble
.Type annotations are checked against the inferred type for the position so you will see errors if the annotated type is not compatible. Parameters are treated as contravariant so you can only provide a subtype of the inferred type - for example you can constrain a parameter type to be non-nullable even if it is in a nullable context. There are cases where the type checker cannot infer a type in which case annotations are necessary.
I know we already have a similar parser for type expressions in hml files. I thought it would be easier to write a new one specialized for this connector and for MongoDB scalar types since it's about 100 LOC.
Type expressions use GraphQL syntax to match types as seen in GraphQL and in hml. There is one addition: I invented a syntax for predicate types,
predicate<ObjectTypeName>
. The parser happens to be written so that if the angle brackets are absent the wordpredicate
will be interpreted as an object type so we don't have a problem if a user want to use an object type named "predicate".On the other hand this parser does not allow object type names that match MongoDB scalar type names.
While I was working on this I noticed some issues with unifying types in the presence of nullability, and with displaying errors when a type annotation can't be unified with inferred constraints for a parameter's context. So I included some fixes in those areas.