-
Notifications
You must be signed in to change notification settings - Fork 65
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
Template tag for EdgeQL #350
Comments
Probably it accepting an array of strings is better since I imagine sometimes such lists would be formed dynamically, and |
With a variadic function you can use the spread operator to pass in an array of identifiers: |
Pretty much any Unicode string is a valid identifier as long as you quote it. The only hard rule is that an ident cannot start with |
I think it's probably safe to add the rest of the types to this list, ie. datetime, local_date/time, duration and bytes, since we can identify them with |
Indeed good call! |
I see draft PR #381 implements this functionality. See also discussion on edgedb/edgedb. This may be premature, but is there a way to expose the result type of a tagged template query to typescript for autocompletion / typechecking purposes? E.g. using |
No, this template tag will not be schema-aware nor can it infer types. That's virtually impossible to implement with just template literals - you should use the query builder if you want inferred types and typechecking. |
Indeed, but it would be possible with a VSCode extension. It would introspect each query at dev-time and tell typescript what type that is |
I'm not sure how that would work exactly, but I've observed some existing solutions in the same space: Option 1One option is a codegen tool that would watch the source for queries tagged with GraphQL libraries have taken this path in the past 1 and seem to have converged on graphql-code-generator which is a centralized codegen integration point that alternate generators can plug into|plugin to. Option 2Out of I prefer Option 2 for edgeql if possible. I expect that automatically adding types to I don't mean to derail this issue, and I think it would still be reasonable to implement the tagged template as described in the original post, and splitting this topic into a second issue. I also think that being able to generate typesafe code by simply tagging edgeql queries could be a big benefit and a reason why the feature requested by this issue should be implemented as a first step. Footnotes |
Is this still desirable given the |
Proposal: provide a template tag for writing sanitized EdgeQL queries.
User input
We'd overload the query methods to support an object-based query format:
{query: string; parameters: {[k:string]: any}}
The cast type will be inferred from the input data according to the following rules:
Array.isArray(data) === true
-> check that contents are homogenous primitives ->array<element-type>
object
->json
string
->str
number
->float64
bigint
->bigint
boolean
->bool
Implicit/assignment casting makes this workable. e.g. Assigning a
float64
to aint16
value will work without an explicit cast.Identifiers
There should be a separate API for specifying identifiers:
edgeql.ident()
. This would verify that the input is a valid identifier with a regex.For convenience this function can be variadic. The inputs will be validated and joined with
", "
.The text was updated successfully, but these errors were encountered: