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

[Question] Does anybody use @semanticNonNull with a federated graph? Is it even possible? #2528

Open
lervag opened this issue Jan 27, 2025 · 2 comments
Labels
federation Issue related to federation support

Comments

@lervag
Copy link
Contributor

lervag commented Jan 27, 2025

I'm working on a subgraph written with Caliban. It mostly works great.

Recently, we've started to test @semanticNonNull, and it also seems to work great when we test it only on the subgraph. However, it seems hard or impossible to actually pass the directive through the supergraph. We use Hive as the router, but I've also tested with Apollo rover. I've tried to use the @composeDirective thing explained here, but it simply does not seem to work as expected.

I'm just curious if anyone else have tried this before and/or if someone knows if this is even possible?

@ghostdogpr ghostdogpr added the federation Issue related to federation support label Jan 27, 2025
@paulpdaniels
Copy link
Collaborator

What exactly isn’t working for you? I don’t actually use it in any of our graphs, but it’s part of the compatibility check from Apollo for compliant subgraphs, so maybe the example here would help? https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/implementations/caliban/src/main/scala/models/package.scala

@lervag
Copy link
Contributor Author

lervag commented Jan 28, 2025

Sorry, I could probably have expanded a bit in my post.

What we do is this:

Now, we want to make @semanticNonNull pass through to the supergraph schema so that our frontends can use the added information. Based on the Apollo docs, I believe the directive is a type system directive. What we find is that the @semanticNonNull directive is dropped at the composition stage. This is the case both with hive gateway and with Apollo rover.

The observed behaviour seems to be what we should expect, though. It seems we need to specify that the directive should be passed through to the supergraph with @composeDirective. So, we tried to hand-change our schema, i.e. we added @composeDirective in our schema:

directive @semanticNonNull on FIELD_DEFINITION

schema
  @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@requires", "@provides", "@external", "@shareable", "@tag", "@inaccessible", "@override", "@extends", "@composeDirective", "@interfaceObject"])
  @link(url: "https://specs.apollo.dev/nullability/v0.2", import: ["@semanticNonNull"])
  @composeDirective(name: "@semanticNonNull")
{
  query: Query
  mutation: Mutation
}

We expected that this would make the directive visible for our frontends. It seems however that the directive does not become visible through introspection or the sdl. Today I investigated further and I notice that rover supergraph compose, we do get a schema that includes the directive. But the composed schema and the schema that is visible through inspection is not the same.

I know this is not a Caliban issue - I was just hoping that someone here might have experience with this and possibly an idea about where to read to understand the observed behaviour.


Just to be clear, when testing the @composeDirective, we actually didn't change the Scala code. We just took the schema from the subgraph and changed it directly to see how that affects the supergraph. The example you provide seems very relevant if we were able to make it work - so thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
federation Issue related to federation support
Projects
None yet
Development

No branches or pull requests

3 participants