-
Notifications
You must be signed in to change notification settings - Fork 79
feat: allow users to customize the TypeScript type of a custom scalar #1313
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
feat: allow users to customize the TypeScript type of a custom scalar #1313
Conversation
packages/generate/src/queries.ts
Outdated
| }, | ||
| ); | ||
|
|
||
| async function analyzeQuery( |
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 think it's fine to expand the existing public function to take options (let's use the existing CommandOptions type instead of this anonymous type) and make it default to {} like you're doing here. The main first-party consumer of this function is just this queries generator, so it'd be weird if the public one was not the one that the queries generator used.
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.
@scotttrinh updated. Didn't use CommandOptions in analyzeQuery because the command options are defined in generate, while analyzeQuery is in the main package. Let me know if that doesn't work for you!
130ab1c to
8fa0759
Compare
scotttrinh
left a comment
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.
👏 Thanks for bearing with me on the back and forth!
|
@scotttrinh no worries at all — I appreciate your responsiveness! |
|
Neat! i'm trying this and because of TS magic i'm not familiar with claude had to add import type {} from "gel"to the |
|
Oh, thanks for the report! What is |
Should've been explicit, i use pnpm exec generate queries --target ts --use-resolved-codec-type --file ./queries/autogenerated && prettier --experimental-cli -w ./queries
// GENERATED by @gel/generate v0.6.4
// This file is automatically generated from .edgeql query files.
// To make changes, edit the source .edgeql file and regenerate.
import type {Executor, ResolvedCodecType} from "gel";
// ...Also // overrides.d.ts
// This import makes this file a module, enabling proper module augmentation
import type {} from "gel"
declare module "gel" {
export interface OverrideCodecType {
"default::ShopHandle": `@${string}`
}
} |
Why?
This PR adds the ability for users of the queries generator to override the TypeScript types of custom scalar variables via
OverrideCodecType. The default scalar types are non-overrideable.Example:
default.gel:findUser.edgeql:Run
generate queries --target ts --use-resolved-codec-typeVerify
findUser.query.tsincludes the overridable types:How?
This PR attempts to implement this functionality in a backwards-compatible way, since
analyzeQueryis technically a public API.1Footnotes
Although it's only used in the queries generator within the repo, it's mentioned in the README as the primary API to build a custom generator, and it looks like other projects are using it. ↩