How to @require @inaccessible fields

I am trying to write a query that uses data across two subgraphs to allow for filtration based on data from both subgraphs, but I do not want to expose the dependent data to the client. If I mark the dependent data as @inaccessible, my query breaks. This seems like it should work based on the language in the docs, especially

Note that Position.z does appear in the supergraph schema, but the API schema enforces which fields clients can include in operations. 

Does this indicate that the @requires must be a publicly accessible query and thus that @inaccessible fields are not available there?

I get the message:

"Cannot add selection of field \"Example.sensitiveUserData\" to selection set of parent type \"Example\" (that does not declare that field)",

Here is my SDL:

subgraph A
type Example @key(fields: "id"){
   id: ID!
   sensitiveUserData: SensitiveUserData @inaccessible
}

type SensitiveUserData {
   age: Int
}

subgraph B
type Example @key(fields: "id"){
   id: ID!
   sensitiveUserData: SensitiveUserData @external
   someDerivedData: DerivedData @requires(fields: "sensitiveUserData { age }")
}

Hello :wave:

Can you clarify where are you getting "Cannot add selection of field \"Example.sensitiveUserData\" to selection set of parent type \"Example\" (that does not declare that field)", error?

This is a valid use case that is supported by the Federation 2.

Are you trying to query for sensitiveUserData field (which will be @inaccessible for end users through Gateway/Router but will passed over to subgraph B when resolving someDerivedData)?

I get this error returned by Gateway to the client when I submit a query that specifies the someDerivedData field. I am not asking for the @inaccessible field. It seems like the error is coming from the @requires field asking for the data somehow. Say something like

query SomeExampleQuery($id: ID!) {
   exampleById(id: $id) {
     someDerivedData {
       someDerivedField
     }
   }
}

Are you using latest Gateway/Router? Which subgraph library are you using? Is your schema importing @inaccessible directive through @link?

We just tested it using apollo-server v4 and it worked as expected.

That could be it…
Subgraph v2.1.1
Gateway v2.1.1
Server 3.10.2 for subgraph A, 3.6.4 for subgraph B.

Is this a v4 specific feature?
I’ll see if I can update to v4.

I believe you are running into 2.1.1 regression: @inaccessible + @requires fails at runtime · Issue #2152 · apollographql/federation · GitHub, which has been fix in the 2.1.3 release of federation. So if you upgrade your dependencies to @apollo/gateway: 2.1.3, this should be fixed (pretty sure this is unrelated to the apollo-server version however).