Skip to content
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

Extend overrides: Add Type Overrides #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

egdelgadillo
Copy link

@egdelgadillo egdelgadillo commented Nov 13, 2021

I wanted a way of having more specificity over every type that is being generated.
This Pull Request extends the capability of overrides by adding a new property, typeOverrides which features:

  1. Ability to set the type for a specific table's column (e.g. users.name: 'SomeType')
  2. Ability to set the types for all columns that match the column name (e.g. name: 'SomeType').
  3. Ability to override the database's default type to include our own (e.g. decimal: 'number').
  4. Types post-processor for all types "*" that match everything after types have been processed and assigned, giving the user the ability to override everything or append data conditionally or unconditionally.

All of these overrides also accept functions as values, to be able to run more complex calculations. They are all enabled by default but can be disabled, giving the user even more capability when combining all those rules.

I decided not to extend the already existing overrides property to be able to separate the concerns, as I'm planning on extending it again in the near future, which rules may conflict with what I just added. Thus, just adding them all inside a new overrides property, to prevent rules from stepping on each other or targeting undesired columns/tables.

Tests have been updated to reflect the new behavior and are now up-to-date.

Most of the changes in main.js are due to styles.

@egdelgadillo egdelgadillo changed the title Extend overrides Extend overrides: Add Type Overrides Nov 15, 2021
@koistya
Copy link
Member

koistya commented Nov 18, 2021

@egdelgadillo what do you think about extending overrides option to support more advanced configs, for example:

overrides: {
  "identity_provider.linkedin": "LinkedIn", // or { name: "LinkedIn" }
  "story.content": { type: "Paragraph[]" },
  "story.views_count": { type: "BigInt" },
}
export type Story = {
  content: Paragraph[];
  viewsCount: BigInt;
}

With the support of shortcuts:

overrides: {
  "*.linkedin": "LinkedIn", // or { name: "LinkedIn" }
  "*.content": { type: "Paragraph[]" },
  "views_count": { type: "BigInt" },
  "*:numeric": { type: "float" },
}

Enable the overriding of the default types, specifying the type for a
single table's column, all columns matching a certain name, a database's
default type, and even modify all types with the "*" selector. They're
enabled by default, but they can also be disabled indivually.

All tests have been updated to reflect the new behavior.
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.

None yet

2 participants