Skip to content

Inject defaults into the planConnection query in the GTFS GraphQL schema#6339

Merged
optionsome merged 41 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:plan-connection-defaults
Feb 19, 2025
Merged

Inject defaults into the planConnection query in the GTFS GraphQL schema#6339
optionsome merged 41 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:plan-connection-defaults

Conversation

@optionsome

@optionsome optionsome commented Dec 17, 2024

Copy link
Copy Markdown
Member

Summary

Inject defaults (either from code or configuration) into the planConnection query in the GTFS GraphQL schema that is outputted through introspection.

This pr also allows to reset searchWindow as null in the planConnection query (in case it has been configured on server).

Issue

No issue

Unit tests

Added tests.

Documentation

In schema

Changelog

From title

Bumping the serialization version id

Not needed

@optionsome optionsome added the !Improvement A functional improvement or micro feature label Dec 17, 2024
@optionsome

Copy link
Copy Markdown
Member Author

We need to decide if using a directive makes sense or should we just use the input type and field names as keys for the translations. Also, have to maybe figure out how to not construct the schema on each request.

@leonardehrenfried

Copy link
Copy Markdown
Member

Can you resolve the conflicts?

@optionsome
optionsome marked this pull request as ready for review December 31, 2024 14:43
@optionsome
optionsome requested a review from a team as a code owner December 31, 2024 14:43
Comment thread application/src/main/java/org/opentripplanner/apis/gtfs/SchemaFactory.java Outdated
@codecov

codecov Bot commented Dec 31, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 71.54812% with 136 lines in your changes missing coverage. Please review.

Project coverage is 70.29%. Comparing base (62b4982) to head (8936d94).
Report is 216 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...pentripplanner/apis/gtfs/DefaultValueInjector.java 72.69% 63 Missing and 8 partials ⚠️
...is/gtfs/mapping/routerequest/StreetModeMapper.java 61.76% 7 Missing and 6 partials ⚠️
...is/gtfs/mapping/routerequest/AccessModeMapper.java 9.09% 9 Missing and 1 partial ⚠️
...ng/routerequest/VehicleOptimizationTypeMapper.java 16.66% 8 Missing and 2 partials ⚠️
...is/gtfs/mapping/routerequest/DirectModeMapper.java 10.00% 8 Missing and 1 partial ⚠️
...is/gtfs/mapping/routerequest/EgressModeMapper.java 11.11% 7 Missing and 1 partial ⚠️
...a/org/opentripplanner/apis/gtfs/SchemaFactory.java 96.00% 4 Missing ⚠️
...ntripplanner/apis/gtfs/configure/SchemaModule.java 0.00% 4 Missing ⚠️
.../gtfs/mapping/routerequest/TransferModeMapper.java 25.00% 2 Missing and 1 partial ⚠️
...entripplanner/apis/gtfs/GraphQLRequestContext.java 0.00% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6339      +/-   ##
=============================================
- Coverage      70.31%   70.29%   -0.02%     
- Complexity     18158    18206      +48     
=============================================
  Files           2058     2062       +4     
  Lines          76939    77262     +323     
  Branches        7771     7779       +8     
=============================================
+ Hits           54097    54309     +212     
- Misses         20088    20185      +97     
- Partials        2754     2768      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@optionsome

Copy link
Copy Markdown
Member Author

We need to decide if using a directive makes sense or should we just use the input type and field names as keys for the translations. Also, have to maybe figure out how to not construct the schema on each request.

We decided to not use directives (however directive wiring is used to inject the defaults). Used dependency injection to avoid constructing the schema on each request.

@optionsome optionsome added this to the 2.7 (next release) milestone Dec 31, 2024
@optionsome optionsome changed the title Add defaults to the planConnection query in the GTFS GraphQL schema Inject defaults into the planConnection query in the GTFS GraphQL schema Dec 31, 2024
t2gran
t2gran previously approved these changes Jan 30, 2025
@optionsome

Copy link
Copy Markdown
Member Author

I'm in process of adding some array and input object defaults as it seems like using them is possible (I thought for some reason that using them wasn't possible). However, I'm slightly struggling with how to deal with resetting allowedNetworks in the context of rental. What I mean is that if someone has configured on the server that ["x", "y"] networks are allowed, it should be possible to define in the query that all networks would be allowed instead of just "x" and "y". Using an empty array to reset this feels wrong and using null doesn't seem possible either because in the context of input fields, the default value isn't always provided by the library and instead the field has null value even though the user did not provide that value.

This is what the bicycle rental preferences look like currently, for example:

Details
"Preferences related to bicycle rental (station based or floating bicycle rental)."
input BicycleRentalPreferencesInput {
  "Rental networks which can be potentially used as part of an itinerary."
  allowedNetworks: [String!]
  "Rental networks which cannot be used as part of an itinerary."
  bannedNetworks: [String!]
  """
  Is it possible to arrive to the destination with a rented bicycle and does it
  come with an extra cost.
  """
  destinationBicyclePolicy: DestinationBicyclePolicyInput
}

We could add a new field to resetting the allowedNetworks (for example allowAllNetworks), but that would feel wrong since you might want to use bannedNetworks. Naming it resetAllowedNetworks on the other hand feels like a weird solution. Maybe grouping the allowed/banned under some filter object would be the best solution as then we could add a allowAllNetworks switch that you would only need to provide if you want to reset the allowedNetworks. If you provide bannedNetworks, it would reset the allowedNetworks. Maybe something like (this is example is like if someone has configured allowedNetworks: ["x", "y"] on the router configuration):

Details
"Preferences related to bicycle rental (station based or floating bicycle rental)."
input BicycleRentalPreferencesInput {
  "Rental networks which can be potentially used as part of an itinerary."
  filter: RentalFilter = {allowedNetworks: ["x", "y"]}
  """
  Is it possible to arrive to the destination with a rented bicycle and does it
  come with an extra cost.
  """
  destinationBicyclePolicy: DestinationBicyclePolicyInput
}

input RentalFilter @oneOf {
"Rental networks which can be potentially used as part of an itinerary."
allowedNetworks: [String!]
"Rental networks which cannot be used as part of an itinerary."
bannedNetworks: [String!]
allowAllNetworks: boolean
}

On the other hand, adding a new filter implementation always feels like a bit sketchy as usually we end up implementing either something too simple or too complex. What if we want to some filter criteria in the future which is complimentary, like propulsion type in combination of networks (i.e. "x" network's HUMAN propulsion type vehicles are allowed).

@optionsome
optionsome dismissed stale reviews from leonardehrenfried and t2gran via ab98348 February 4, 2025 08:47
Comment thread doc/user/RouteRequest.md
| [maxDirectStreetDuration](#rd_maxDirectStreetDuration) | `duration` | This is the maximum duration for a direct street search for each mode. | *Optional* | `"PT4H"` | 2.1 |
| [maxJourneyDuration](#rd_maxJourneyDuration) | `duration` | The expected maximum time a journey can last across all possible journeys for the current deployment. | *Optional* | `"PT24H"` | 2.1 |
| modes | `string` | The set of access/egress/direct/transit modes to be used for the route search. | *Optional* | `"TRANSIT,WALK"` | 2.0 |
| modes | `string` | The set of access/egress/direct/transfer modes (separated by a comma) to be used for the route search. | *Optional* | `"WALK"` | 2.0 |

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

While testing some changes I noticed we don't actually support providing default transit modes in config.

}

public static GraphQLTypes.GraphQLTransitMode map(TransitMode mode) {
return switch (mode) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where did these mappers live beforehand?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For some reason I forgot to check and there was already one, but I removed it in favor of this in ef7018a. However, the previous version had null checks which I'm not sure are necessary as the route mode doesn't seem to be nullable.

@optionsome
optionsome merged commit 438decc into opentripplanner:dev-2.x Feb 19, 2025
@optionsome
optionsome deleted the plan-connection-defaults branch February 19, 2025 14:36
t2gran pushed a commit that referenced this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Improvement A functional improvement or micro feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants