Prevent non-core-feature elements from being marked @inaccessible if referenced by core feature elements #1769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So currently, the following supergraph schema does not error when being converted to an API schema:
This is because
removeInaccessibleElements()
is aware that core feature elements aren't exposed in the API schema, and won't error when an@inaccessible
non-core feature element is referenced by a core feature element.Currently, no Apollo core spec to my knowledge introduces core feature elements that can reference non-built-in, non-core feature elements. And since composition doesn't allow user-defined core specs at the moment, that means nothing should be relying on this behavior for now.
However:
So in order to prevent exposed core feature directives from also exposing
@inaccessible
feature elements in the API schema, we need to either:removeInaccessibleElements()
to be aware of which core feature elements are exposed in the API schema.removeInaccessibleElements()
to forbid non-core-feature elements from being marked@inaccessible
if referenced by core feature elements.I've arbitrarily chosen Option 2 in this PR because:
I'd also be fine with Option 1 (e.g. if folks want to leave the possibility open for this kind of referencing in user-defined core specs). Regardless of what we choose, the main thing I'd like to prevent is the leaking of
@inaccessible
feature elements in the API schema.Note that the error messaging for when this edge case occurs isn't great in this PR (it tells the user the referencing element is in the API schema, regardless of whether it actually is). I could return a trilean enum from
isInAPISchema()
(using the third value for "maybe") and update messaging if folks would prefer, or some other means of improving the messaging.