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

Schema transformations #2218

Merged
merged 8 commits into from
May 9, 2024
Merged

Schema transformations #2218

merged 8 commits into from
May 9, 2024

Conversation

ghostdogpr
Copy link
Owner

@ghostdogpr ghostdogpr commented May 8, 2024

Closes #130

Adds the ability to transform types of an existing schema:

  • rename types, fields and arguments
  • filter interfaces, fields and arguments
  • custom transformations

Example usage:

api
  .transform(Transformer.RenameType("InnerObject" -> "Renamed"))
  .transform(Transformer.ExcludeField("Query" -> "b"))

ghostdogpr and others added 6 commits February 19, 2024 09:36
@kyri-petrou
Copy link
Collaborator

kyri-petrou commented May 8, 2024

As a side note, I think we should either document for users to avoid this pattern, or we should optimize for it. With a small number of cases it won't make a big difference, but it'll add up if they start doing this with a lot of them.

api
  .transform(Transformer.RenameType("Foo" -> "Bar"))
  .transform(Transformer.RenameType("Bar" -> "Baz"))
  .transform(Transformer.RenameType("Bla" -> "Bra"))

EDIT: For completeness, this is the most performant implementation:

api
  .transform(Transformer.RenameType(
    "Foo" -> "Bar",
    "Bar" -> "Baz",
    "Bla" -> "Bra",
))

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

Love it ❤️

I have a bunch of places I can use this at $WORK so can start using it once we merge in and report any potential issues.

I think given that this is a really great feature, we should just mark the next release as 2.7.0 and disable MiMa. 2.6.0 doesn't seem to have any reported issues so far so I'm hopeful we won't need to do any patch releases soon

@ghostdogpr
Copy link
Owner Author

The PR about nullability also breaks mima so we can ship these 2 together. Let's disable mima as you said.

Let me give it a final review before merging 🙏

@ghostdogpr ghostdogpr merged commit ea4776d into series/2.x May 9, 2024
10 checks passed
@ghostdogpr ghostdogpr deleted the transformers-v2 branch May 9, 2024 00:33
XiNiHa pushed a commit to XiNiHa/caliban that referenced this pull request May 11, 2024
* Add transformers

* Optimize transformers

* Optimize and cleanup API

* Make Scala 2.12 happy

* Cleanups

* Pre-check whether to apply transformers in Transformer.Combined

---------

Co-authored-by: Kyri Petrou <[email protected]>
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.

Support for schema transformations
2 participants