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

Support for schema transformations #130

Closed
ghostdogpr opened this issue Dec 19, 2019 · 6 comments · Fixed by #2218
Closed

Support for schema transformations #130

ghostdogpr opened this issue Dec 19, 2019 · 6 comments · Fixed by #2218
Assignees
Labels
enhancement New feature or request server Issue related to caliban server

Comments

@ghostdogpr
Copy link
Owner

Something similar to this Apollo-server feature: https://www.apollographql.com/docs/apollo-server/features/schema-transforms/

The current problem is that Caliban currently stores runtime schema into this object:

case class Operation[-R](opType: __Type, plan: Step[R])

__Type matches the graphql type used by introspection, while Step is a description of a computation, that might require running some effects to get the underlying steps. If you want to remove or rename a field, it needs to be applied in both structures, which isn't really possible in the case of Step.

We need to think of a different way of encoding the resolver to support this feature. Maybe Step is generated too early and there should be something in between.

@ghostdogpr
Copy link
Owner Author

ghostdogpr commented Dec 19, 2019

An alternative approach could be to introduce a sealed trait Transformation with a list of pre-identified cases (which is what is done in Apollo Server), and apply the changes ourselves case by case on both __Type (initially) and Step (during execution). Only ObjectStep might be affected because it's the only one that contains type names and a list of fields.

I'll sketch this with a simple transformation like renaming types.

@ghostdogpr
Copy link
Owner Author

Did a proof of concept that seems OK with the following API:

api
  .transform(Transformer.RenameType(t => if (t.contains("Queries")) Some("QueriesYOLO") else None))
  .transform(Transformer.FilterType(t => t != "character"))

@ghostdogpr ghostdogpr added the enhancement New feature or request label Feb 23, 2020
@ghostdogpr ghostdogpr self-assigned this Apr 19, 2020
@ghostdogpr ghostdogpr added server Issue related to caliban server core and removed schema labels Sep 12, 2020
@DGolubets
Copy link

Any progress on this?
Seems to be a handy feature when using federation.

@ghostdogpr
Copy link
Owner Author

Any progress on this? Seems to be a handy feature when using federation.

No one manifested interest so far so I didn't go further, but I could potentially resurrect my old prototype. I can't find the Apollo docs anymore but found this https://the-guild.dev/graphql/stitching/docs/transforms

@DGolubets
Copy link

Makes me wonder how many people actually use Apollo federation..

I just finished merging our APIs into a super-graph for use with Apollo Router. I was able to sort the conflicts by making some types sharable and wrapping queries\mutations so far. Nevertheless I got uneasy feeling that every time I modify a sub-graph service I might introduce a new conflict.

With your proposed feature I could just add a prefix to every type name.

@frekw
Copy link
Collaborator

frekw commented Feb 3, 2023

@DGolubets we use Apollo federation. We run schema validation vs the supergraph in CI to avoid introducing conflicts / breaking changes (via the rover cli tool).

It's also very possible to share types between subgraphs, esp. so with federation v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Issue related to caliban server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants