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

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

Open
wants to merge 22 commits into
base: dev-2.x
Choose a base branch
from

Conversation

optionsome
Copy link
Member

@optionsome optionsome commented Dec 17, 2024

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
Copy link
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
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
* Service for fetching the {@link GraphQLSchema}. The purpose of this class is to avoid
* reconstructing the schema on each request.
*/
public class SchemaService {
Copy link
Member Author

Choose a reason for hiding this comment

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

Is it ok that this is just a class or do we need an interface?

Copy link
Member

Choose a reason for hiding this comment

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

Do we even need it at all? If we make the binding @singleton (you already do that) then there should only be a single instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

@t2gran mentioned in some developer meeting that this should be put in a service but I agree that the service might add an unnecessary layer here.

Copy link
Member

Choose a reason for hiding this comment

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

Have we decided that we want this?

} catch (Exception e) {
LOG.error("Unable to build GTFS GraphQL Schema", e);
}
return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we return null or throw some exception here?

Copy link
Member

Choose a reason for hiding this comment

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

I would throw an exception. Returning null will just cause a more confusing NPE somehwere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

The schema is built on the first request that comes to the server. I would prefer to build it even before the server starts serving requests so if there is some issue, it could crash the server. Do you have any clue how that could be achieved?

Copy link
Member

Choose a reason for hiding this comment

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

I think you have to call the method eagerly. I believe that Dagger instantiates the dependencies lazily.

Copy link
Member Author

Choose a reason for hiding this comment

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

What could be a good place to call it eagerly from?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe here?

private Application createApplication() {
LOG.info("Wiring up and configuring server.");
setupTransitRoutingServer();
return new OTPWebApplication(routerConfig().server(), this::createServerContext);
}

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, there is already a unit test so I'm not sure how necessary it is.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 89.71429% with 18 lines in your changes missing coverage. Please review.

Project coverage is 69.81%. Comparing base (72019c0) to head (69de270).
Report is 42 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...ner/standalone/configure/ConstructApplication.java 0.00% 6 Missing ⚠️
...a/org/opentripplanner/apis/gtfs/SchemaFactory.java 95.87% 4 Missing ⚠️
...ntripplanner/apis/gtfs/configure/SchemaModule.java 0.00% 4 Missing ⚠️
...pentripplanner/apis/gtfs/DefaultValueInjector.java 96.66% 1 Missing and 1 partial ⚠️
...entripplanner/apis/gtfs/GraphQLRequestContext.java 0.00% 1 Missing ⚠️
...standalone/server/DefaultServerRequestContext.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6339      +/-   ##
=============================================
+ Coverage      69.79%   69.81%   +0.02%     
- Complexity     17943    17985      +42     
=============================================
  Files           2046     2049       +3     
  Lines          76685    76747      +62     
  Branches        7829     7834       +5     
=============================================
+ Hits           53520    53582      +62     
+ Misses         20423    20422       -1     
- Partials        2742     2743       +1     

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

@optionsome
Copy link
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
@@ -41,11 +41,11 @@ public static RouteRequest toRouteRequest(
request.setFrom(parseGenericLocation(args.getGraphQLOrigin()));
request.setTo(parseGenericLocation(args.getGraphQLDestination()));
request.setLocale(GraphQLUtils.getLocale(environment, args.getGraphQLLocale()));
if (args.getGraphQLSearchWindow() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

What is this change for?

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

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

If we say that we need the service, I'm fine with it. I don't think it is necessary though.

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

Successfully merging this pull request may close these issues.

2 participants