Skip to content

DRAFT: Optional chaining for selection syntax #7637

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

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

andrewmcgivery
Copy link
Contributor

Ignore for now... this is an exploration. :)


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

Copy link
Contributor

github-actions bot commented Jun 6, 2025

@andrewmcgivery, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

@apollo-librarian
Copy link

apollo-librarian bot commented Jun 9, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 19 changed, 0 removed
* graphos/routing/(latest)/cloud/subscriptions.mdx
* graphos/routing/(latest)/configuration/yaml.mdx
* graphos/routing/(latest)/observability/telemetry/metrics-exporters/prometheus.mdx
* graphos/routing/(latest)/observability/telemetry/trace-exporters/overview.mdx
* graphos/routing/(latest)/operations/subscriptions/overview.mdx
* graphos/routing/(latest)/operations/subscriptions/configuration.mdx
* graphos/routing/(latest)/operations/defer.mdx
* graphos/routing/(latest)/operations/file-upload.mdx
* graphos/routing/(latest)/performance/caching/entity.mdx
* graphos/routing/(latest)/performance/caching/in-memory.mdx
* graphos/routing/(latest)/query-planning/native-query-planner.mdx
* graphos/routing/(latest)/security/csrf.mdx
* graphos/routing/(latest)/security/demand-control.mdx
* graphos/routing/(latest)/security/authorization.mdx
* graphos/routing/(latest)/security/subgraph-authentication.mdx
* graphos/routing/(latest)/security/persisted-queries.mdx
* graphos/routing/(latest)/graphos-reporting.mdx
* graphos/routing/(latest)/uplink.mdx
* graphos/routing/(latest)/license.mdx

Build ID: 374c9a6cde711139889816dd

URL: https://www.apollographql.com/docs/deploy-preview/374c9a6cde711139889816dd

source_id,
);
// Make result nullable since optional chaining can produce null
Shape::one([result_shape, Shape::none()], vec![])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Difference between this approach versus:

                if input_shape.is_null() {
                    // TODO Somehow copy names from input_shape to this new
                    // Shape::none() shape?
                    (Shape::none(), None)
                } else {
                    // TODO This should return input_shape.question() once we
                    // support that new child shape method.
                    // (input_shape.question(), Some(tail))
                    (input_shape, Some(tail))
                }

PathList::Question(continuation) => {
// Universal null check for any operation after ?
if data.is_null() {
(Some(JSON::Null), vec![])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this actually be None?

@@ -553,6 +553,10 @@ pub(super) enum PathList {
// middle/tail (not the beginning) of a PathSelection.
Method(WithRange<String>, Option<MethodArgs>, WithRange<PathList>),

// Universal null guard that can wrap any path continuation.
// If data is null, returns null instead of continuing with the wrapped operation.
Question(WithRange<PathList>),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ben's prototype had another param where The firstAdd commentMore actions parameter wraps the range of the ? token. but I am unclear as to why.

It's probably related to why Ben's version below also had depth + 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But also looking at his code it seems like the first param is never actually used. 🤔

@andrewmcgivery
Copy link
Contributor Author

andrewmcgivery commented Jun 9, 2025

EDIT: This has been resolved after discussion with Ben. :)

In apply_to.rs, Ben's code has a change to the Property {} not found in {} logic. I think this is making it not return errors on not found properties if they are immediately followed by a ? since ? applies that whatever comes immediately before it is infact nullable and so not an error if not found at all.

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.

1 participant