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 16 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.

} 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 90.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 69.82%. Comparing base (e890466) to head (813bbbf).
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.91% 4 Missing ⚠️
...is/gtfs/service/configure/SchemaServiceModule.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.85%   69.82%   -0.04%     
- Complexity     17926    17982      +56     
=============================================
  Files           2035     2046      +11     
  Lines          76509    76726     +217     
  Branches        7825     7835      +10     
=============================================
+ Hits           53443    53571     +128     
- Misses         20327    20412      +85     
- Partials        2739     2743       +4     

☔ 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
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