use of graphql.schema.GraphQLNamedOutputType in project OpenTripPlanner by opentripplanner.
the class TransmodelGraphQLSchema method create.
@SuppressWarnings("unchecked")
private GraphQLSchema create() {
/*
multilingualStringType, validityPeriodType, infoLinkType, bookingArrangementType, systemNoticeType,
linkGeometryType, serverInfoType, authorityType, operatorType, noticeType
*/
// Framework
GraphQLOutputType multilingualStringType = MultilingualStringType.create();
GraphQLObjectType validityPeriodType = ValidityPeriodType.create(gqlUtil);
GraphQLObjectType infoLinkType = InfoLinkType.create();
GraphQLOutputType bookingArrangementType = BookingArrangementType.create(gqlUtil);
GraphQLOutputType systemNoticeType = SystemNoticeType.create();
GraphQLOutputType linkGeometryType = PointsOnLinkType.create();
GraphQLOutputType serverInfoType = ServerInfoType.create();
GraphQLOutputType authorityType = AuthorityType.create(LineType.REF, PtSituationElementType.REF);
GraphQLOutputType operatorType = OperatorType.create(LineType.REF, ServiceJourneyType.REF);
GraphQLOutputType noticeType = NoticeType.create();
// Stop
GraphQLOutputType tariffZoneType = TariffZoneType.createTZ();
GraphQLInterfaceType placeInterface = PlaceInterfaceType.create(QuayType.REF, new GraphQLTypeReference(BikeRentalStationType.NAME), new GraphQLTypeReference(BikeParkType.NAME));
GraphQLOutputType bikeRentalStationType = BikeRentalStationType.create(placeInterface);
GraphQLOutputType bikeParkType = BikeParkType.createB(placeInterface);
// GraphQLOutputType carParkType = new GraphQLTypeReference("CarPark");
GraphQLOutputType stopPlaceType = StopPlaceType.create(placeInterface, QuayType.REF, tariffZoneType, EstimatedCallType.REF, gqlUtil);
GraphQLOutputType quayType = QuayType.create(placeInterface, stopPlaceType, LineType.REF, JourneyPatternType.REF, EstimatedCallType.REF, PtSituationElementType.REF, tariffZoneType, gqlUtil);
GraphQLNamedOutputType quayAtDistance = QuayAtDistanceType.createQD(quayType, relay);
// GraphQLNamedOutputType placeAtDistanceType = PlaceAtDistanceType.create(relay);
// Network
GraphQLObjectType presentationType = PresentationType.create();
GraphQLOutputType destinationDisplayType = DestinationDisplayType.create();
GraphQLOutputType lineType = LineType.create(bookingArrangementType, authorityType, operatorType, noticeType, quayType, presentationType, JourneyPatternType.REF, ServiceJourneyType.REF, PtSituationElementType.REF);
GraphQLOutputType interchangeType = InterchangeType.create(lineType, ServiceJourneyType.REF);
// Timetable
GraphQLNamedOutputType ptSituationElementType = PtSituationElementType.create(authorityType, quayType, lineType, ServiceJourneyType.REF, multilingualStringType, validityPeriodType, infoLinkType, relay);
GraphQLOutputType journeyPatternType = JourneyPatternType.create(linkGeometryType, noticeType, quayType, lineType, ServiceJourneyType.REF, ptSituationElementType, gqlUtil);
GraphQLOutputType estimatedCallType = EstimatedCallType.create(bookingArrangementType, noticeType, quayType, destinationDisplayType, ptSituationElementType, ServiceJourneyType.REF, gqlUtil);
GraphQLOutputType serviceJourneyType = ServiceJourneyType.create(bookingArrangementType, linkGeometryType, operatorType, noticeType, quayType, lineType, ptSituationElementType, journeyPatternType, estimatedCallType, TimetabledPassingTimeType.REF, gqlUtil);
GraphQLOutputType timetabledPassingTime = TimetabledPassingTimeType.create(bookingArrangementType, noticeType, quayType, destinationDisplayType, serviceJourneyType, gqlUtil);
GraphQLInputObjectType modesInputType = GraphQLInputObjectType.newInputObject().name("Modes").description("Input format for specifying which modes will be allowed for this search. " + "If this element is not present, it will default to accessMode/egressMode/directMode " + "of foot and all transport modes will be allowed.").field(GraphQLInputObjectField.newInputObjectField().name("accessMode").description("The mode used to get from the origin to the access stops in the transit " + "network the transit network (first-mile). If the element is not present or null," + "only transit that can be immediately boarded from the origin will be used.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("egressMode").description("The mode used to get from the egress stops in the transit network to" + "the destination (last-mile). If the element is not present or null," + "only transit that can immediately arrive at the origin will be used.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("directMode").description("The mode used to get from the origin to the destination directly, " + "without using the transit network. If the element is not present or null," + "direct travel without using transit will be disallowed.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("transportMode").description("The allowed modes for the transit part of the trip. Use an empty list " + "to disallow transit for this search. If the element is not present or null, " + "it will default to all transport modes.").type(new GraphQLList(TRANSPORT_MODE)).build()).build();
GraphQLOutputType tripType = createPlanType(bookingArrangementType, interchangeType, linkGeometryType, systemNoticeType, authorityType, operatorType, bikeRentalStationType, quayType, estimatedCallType, lineType, serviceJourneyType, ptSituationElementType);
GraphQLInputObjectType preferredInputType = GraphQLInputObjectType.newInputObject().name("InputPreferred").description("Preferences for trip search.").field(GqlUtil.newIdListInputField("lines", "Set of ids of lines preferred by user.")).field(GqlUtil.newIdListInputField("authorities", "Set of ids of authorities preferred by user.")).field(GraphQLInputObjectField.newInputObjectField().name("otherThanPreferredLinesPenalty").description("Penalty added for using a line that is not preferred if user has set any line as preferred. In number of seconds that user is willing to wait for preferred line.").type(Scalars.GraphQLInt).defaultValue(routing.request.otherThanPreferredRoutesPenalty).build()).build();
GraphQLInputObjectType unpreferredInputType = GraphQLInputObjectType.newInputObject().name("InputUnpreferred").description("Negative preferences for trip search. Unpreferred elements may still be used in suggested trips if alternatives are not desirable, see InputBanned for hard limitations.").field(GqlUtil.newIdListInputField("lines", "Set of ids of lines user prefers not to use.")).field(GqlUtil.newIdListInputField("authorities", "Set of ids of authorities user prefers not to use.")).build();
GraphQLInputObjectType bannedInputType = GraphQLInputObjectType.newInputObject().name("InputBanned").description("Filter trips by disallowing lines involving certain " + "elements. If both lines and authorities are specified, only one must be valid " + "for each line to be banned. If a line is both banned and whitelisted, " + "it will be counted as banned.").field(GqlUtil.newIdListInputField("lines", "Set of ids for lines that should not be used")).field(GqlUtil.newIdListInputField("authorities", "Set of ids for authorities that should not be used")).field(GqlUtil.newIdListInputField("quays", "Set of ids of quays that should not be allowed for boarding or alighting. Trip patterns that travel through the quay will still be permitted.")).field(GqlUtil.newIdListInputField("quaysHard", "Set of ids of quays that should not be allowed for boarding, alighting or traveling thorugh.")).field(GqlUtil.newIdListInputField("serviceJourneys", "Set of ids of service journeys that should not be used.")).build();
/*
GraphQLInputObjectType transportSubmodeFilterInputType = GraphQLInputObjectType.newInputObject()
.name("TransportSubmodeFilter")
.description("Filter trips by allowing only certain transport submodes per mode.")
.field(GraphQLInputObjectField.newInputObjectField()
.name("transportMode")
.description("Set of ids for lines that should be used")
.type(new GraphQLNonNull(TRANSPORT_MODE))
.build())
.field(GraphQLInputObjectField.newInputObjectField()
.name("transportSubmodes")
.description("Set of transport submodes allowed for transport mode.")
.type(new GraphQLNonNull(new GraphQLList(TRANSPORT_SUBMODE)))
.build())
.build();
*/
GraphQLFieldDefinition tripFieldType = GraphQLFieldDefinition.newFieldDefinition().name("trip").description("Input type for executing a travel search for a trip between two locations. Returns trip patterns describing suggested alternatives for the trip.").type(tripType).argument(GraphQLArgument.newArgument().name("dateTime").description("Date and time for the earliest time the user is willing to start the journey (if arriveBy=false/not set) or the latest acceptable time of arriving (arriveBy=true). Defaults to now").type(gqlUtil.dateTimeScalar).build()).argument(GraphQLArgument.newArgument().name("searchWindow").description("The length of the search-window in minutes. This is normally dynamically calculated by the server, but you may override this by setting it. The search-window used in a request is returned in the response metadata. To get the \"next page\" of trips use the metadata(searchWindowUsed and nextWindowDateTime) to create a new request. If not provided the value is resolved depending on the other input parameters, available transit options and realtime changes.").type(Scalars.GraphQLInt).build()).argument(GraphQLArgument.newArgument().name("from").description("The start location").type(new GraphQLNonNull(LocationInputType.INPUT_TYPE)).build()).argument(GraphQLArgument.newArgument().name("to").description("The end location").type(new GraphQLNonNull(LocationInputType.INPUT_TYPE)).build()).argument(GraphQLArgument.newArgument().name("wheelchairAccessible").description("Whether the trip must be wheelchair accessible. NOT IMPLEMENTED").type(Scalars.GraphQLBoolean).defaultValue(routing.request.wheelchairAccessible).build()).argument(GraphQLArgument.newArgument().name("numTripPatterns").description("The maximum number of trip patterns to return for this search " + "window. This may cause relevant trips to be missed, so it is preferable " + "to set this high and use other filtering options instead.").defaultValue(routing.request.numItineraries).type(Scalars.GraphQLInt).build()).argument(GraphQLArgument.newArgument().name("walkSpeed").description("The maximum walk speed along streets, in meters per second").type(Scalars.GraphQLFloat).defaultValue(routing.request.walkSpeed).build()).argument(GraphQLArgument.newArgument().name("bikeSpeed").description("The maximum bike speed along streets, in meters per second").type(Scalars.GraphQLFloat).defaultValue(routing.request.bikeSpeed).build()).argument(GraphQLArgument.newArgument().name("bicycleOptimisationMethod").description("The set of characteristics that the user wants to optimise for during bicycle searches -- defaults to " + reverseMapEnumVal(EnumTypes.BICYCLE_OPTIMISATION_METHOD, routing.request.optimize)).type(EnumTypes.BICYCLE_OPTIMISATION_METHOD).defaultValue(routing.request.optimize).build()).argument(GraphQLArgument.newArgument().name("arriveBy").description("Whether the trip should depart at dateTime (false, the default), or arrive at dateTime.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.arriveBy).build()).argument(GraphQLArgument.newArgument().name("preferred").description("Parameters for indicating authorities or lines that preferably should be used in trip patters. A cost is applied to boarding nonpreferred authorities or lines (otherThanPreferredRoutesPenalty).").type(preferredInputType).build()).argument(GraphQLArgument.newArgument().name("unpreferred").description("Parameters for indicating authorities or lines that preferably should not be used in trip patters. A cost is applied to boarding nonpreferred authorities or lines (otherThanPreferredRoutesPenalty).").type(unpreferredInputType).build()).argument(GraphQLArgument.newArgument().name("banned").description("Banned").description("Parameters for indicating authorities, lines or quays not be used in the trip patterns").type(bannedInputType).build()).argument(GraphQLArgument.newArgument().name("whiteListed").description("Whitelisted").description("Parameters for indicating the only authorities, lines or quays to be used in the trip patterns").type(JourneyWhiteListed.INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("transferPenalty").description("An extra penalty added on transfers (i.e. all boardings except the first one). The transferPenalty is used when a user requests even less transfers. In the latter case, we don't actually optimise for fewest transfers, as this can lead to absurd results. Consider a trip in New York from Grand Army Plaza (the one in Brooklyn) to Kalustyan's at noon. The true lowest transfers trip pattern is to wait until midnight, when the 4 train runs local the whole way. The actual fastest trip pattern is the 2/3 to the 4/5 at Nevins to the 6 at Union Square, which takes half an hour. Even someone optimise for fewest transfers doesn't want to wait until midnight. Maybe they would be willing to walk to 7th Ave and take the Q to Union Square, then transfer to the 6. If this takes less than transferPenalty seconds, then that's what we'll return.").type(Scalars.GraphQLInt).defaultValue(routing.request.transferCost).build()).argument(GraphQLArgument.newArgument().name("modes").description("The set of access/egress/direct/transit modes to be used for " + "this search.").type(modesInputType).build()).argument(GraphQLArgument.newArgument().name("transferSlack").description("An expected transfer time (in seconds) that specifies the amount of time that must pass between exiting one public transport vehicle and boarding another. This time is in addition to time it might take to walk between stops.").type(Scalars.GraphQLInt).defaultValue(routing.request.transferSlack).build()).argument(GraphQLArgument.newArgument().name("boardSlackDefault").description(TransportModeSlack.boardSlackDescription("boardSlackList")).type(Scalars.GraphQLInt).defaultValue(routing.request.boardSlack).build()).argument(GraphQLArgument.newArgument().name("boardSlackList").description(TransportModeSlack.slackByGroupDescription("boardSlack", routing.request.boardSlackForMode)).type(TransportModeSlack.SLACK_LIST_INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("alightSlackDefault").description(TransportModeSlack.alightSlackDescription("alightSlackList")).type(Scalars.GraphQLInt).defaultValue(routing.request.alightSlack).build()).argument(GraphQLArgument.newArgument().name("alightSlackList").description(TransportModeSlack.slackByGroupDescription("alightSlack", routing.request.alightSlackForMode)).type(TransportModeSlack.SLACK_LIST_INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("maximumTransfers").description("Maximum number of transfers").type(Scalars.GraphQLInt).defaultValue(routing.request.maxTransfers).build()).argument(GraphQLArgument.newArgument().name("ignoreRealtimeUpdates").description("When true, realtime updates are ignored during this search.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.ignoreRealtimeUpdates).build()).argument(GraphQLArgument.newArgument().name("locale").type(EnumTypes.LOCALE).defaultValue("no").build()).argument(GraphQLArgument.newArgument().name("transitGeneralizedCostLimit").description("Set a relative limit for all transit itineraries. The limit " + "is calculated based on the best transit itinerary generalized-cost. " + "Itineraries without transit legs are excluded from this filter. " + "Example: f(x) = 3600 + 2.0 x. If the lowest cost returned is 10 000, " + "then the limit is set to: 3 600 + 2 * 10 000 = 26 600. Then all " + "itineraries with at least one transit leg and a cost above 26 600 " + "is removed from the result. Default: " + RequestFunctions.serialize(routing.request.transitGeneralizedCostLimit)).type(gqlUtil.doubleFunctionScalar).build()).argument(GraphQLArgument.newArgument().name("walkReluctance").description("Walk cost is multiplied by this value. This is the main parameter to use for limiting walking.").type(Scalars.GraphQLFloat).defaultValue(routing.request.walkReluctance).build()).argument(GraphQLArgument.newArgument().name("debugItineraryFilter").description("Debug the itinerary-filter-chain. The filters will mark itineraries as deleted, but NOT delete them when this is enabled.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.debugItineraryFilter).build()).dataFetcher(environment -> new TransmodelGraphQLPlanner().plan(environment)).build();
// carParkType = GraphQLObjectType.newObject()
// .name("CarPark")
// .withInterface(placeInterface)
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("id")
// .type(new GraphQLNonNull(Scalars.GraphQLID))
// .dataFetcher(environment -> ((CarPark) environment.getSource()).id)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("name")
// .type(new GraphQLNonNull(Scalars.GraphQLString))
// .dataFetcher(environment -> ((CarPark) environment.getSource()).name)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("capacity")
// .type(Scalars.GraphQLInt)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).maxCapacity)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("spacesAvailable")
// .type(Scalars.GraphQLInt)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).spacesAvailable)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("realtimeOccupancyAvailable")
// .type(Scalars.GraphQLBoolean)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).realTimeData)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("longitude")
// .type(Scalars.GraphQLFloat)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).x)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("latitude")
// .type(Scalars.GraphQLFloat)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).y)
// .build())
// .build();
// GraphQLInputObjectType filterInputType = GraphQLInputObjectType.newInputObject()
// .name("InputFilters")
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("quays")
// .description("Quays to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("lines")
// .description("Lines to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("bikeRentalStations")
// .description("Bike rentals to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("bikeParks")
// .description("Bike parks to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("carParks")
// .description("Car parks to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .build();
// String multiModalMode=environment.getArgument("multiModalMode");
// if ("parent".equals(multiModalMode)){
// stops = stops.map(s -> getParentStopPlace(s).orElse(s));
// }
// List<Stop> stopList=stops.distinct().collect(Collectors.toList());
// if ("all".equals(multiModalMode)) {
// stopList.addAll(stopList.stream().map(s -> getParentStopPlace(s).orElse(null)).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
// }
// return stopList;
// else {
// return index.getLuceneIndex().query(environment.getArgument("name"), true, true, false)
// .stream()
// .map(result -> index.stopForId.get(mapper.fromIdString(result.id)));
// }
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("nearest")
// .description(
// "Get all places (quays, stop places, car parks etc. with coordinates) within the specified radius from a location. The returned type has two fields place and distance. The search is done by walking so the distance is according to the network of walkables.")
// .type(relay.connectionType("placeAtDistance",
// relay.edgeType("placeAtDistance", placeAtDistanceType, null, new ArrayList<>()),
// new ArrayList<>()))
// .argument(GraphQLArgument.newArgument()
// .name("latitude")
// .description("Latitude of the location")
// .type(new GraphQLNonNull(Scalars.GraphQLFloat))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("longitude")
// .description("Longitude of the location")
// .type(new GraphQLNonNull(Scalars.GraphQLFloat))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("maximumDistance")
// .description("Maximum distance (in meters) to search for from the specified location. Default is 2000m.")
// .defaultValue(2000)
// .type(Scalars.GraphQLInt)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("maximumResults")
// .description("Maximum number of results. Search is stopped when this limit is reached. Default is 20.")
// .defaultValue(20)
// .type(Scalars.GraphQLInt)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByPlaceTypes")
// .description("Only include places of given types if set. Default accepts all types")
// .defaultValue(Arrays.asList(TransmodelPlaceType.values()))
// .type(new GraphQLList(filterPlaceTypeEnum))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByModes")
// .description("Only include places that include this mode. Only checked for places with mode i.e. quays, departures.")
// .type(new GraphQLList(modeEnum))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByInUse")
// .description("Only affects queries for quays and stop places. If true only quays and stop places with at least one visiting line are included.")
// .type(Scalars.GraphQLBoolean)
// .defaultValue(Boolean.FALSE)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByIds")
// .description("Only include places that match one of the given ids.")
// .type(filterInputType)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("multiModalMode")
// .type(multiModalModeEnum)
// .description("MultiModalMode for query. To control whether multi modal parent stop places, their mono modal children or both are included in the response." +
// " Does not affect mono modal stop places that do not belong to a multi modal stop place. Only applicable for placeType StopPlace")
// .defaultValue("parent")
// .build())
// .argument(relay.getConnectionFieldArguments())
// .dataFetcher(environment -> {
// List<FeedScopedId> filterByStops = null;
// List<FeedScopedId> filterByRoutes = null;
// List<String> filterByBikeRentalStations = null;
// List<String> filterByBikeParks = null;
// List<String> filterByCarParks = null;
// @SuppressWarnings("rawtypes")
// Map filterByIds = environment.getArgument("filterByIds");
// if (filterByIds != null) {
// filterByStops = toIdList(((List<String>) filterByIds.get("quays")));
// filterByRoutes = toIdList(((List<String>) filterByIds.get("lines")));
// filterByBikeRentalStations = filterByIds.get("bikeRentalStations") != null ? (List<String>) filterByIds.get("bikeRentalStations") : Collections.emptyList();
// filterByBikeParks = filterByIds.get("bikeParks") != null ? (List<String>) filterByIds.get("bikeParks") : Collections.emptyList();
// filterByCarParks = filterByIds.get("carParks") != null ? (List<String>) filterByIds.get("carParks") : Collections.emptyList();
// }
//
// List<TraverseMode> filterByTransportModes = environment.getArgument("filterByModes");
// List<TransmodelPlaceType> placeTypes = environment.getArgument("filterByPlaceTypes");
// if (CollectionUtils.isEmpty(placeTypes)) {
// placeTypes = Arrays.asList(TransmodelPlaceType.values());
// }
// List<GraphIndex.PlaceType> filterByPlaceTypes = mapper.mapPlaceTypes(placeTypes);
//
// // Need to fetch more than requested no of places if stopPlaces are allowed, as this requires fetching potentially multiple quays for the same stop place and mapping them to unique stop places.
// int orgMaxResults = environment.getArgument("maximumResults");
// int maxResults = orgMaxResults;
// if (placeTypes != null && placeTypes.contains(TransmodelPlaceType.STOP_PLACE)) {
// maxResults *= 5;
// }
//
// List<GraphIndex.PlaceAndDistance> places;
// try {
// places = index.findClosestPlacesByWalking(
// environment.getArgument("latitude"),
// environment.getArgument("longitude"),
// environment.getArgument("maximumDistance"),
// maxResults,
// filterByTransportModes,
// filterByPlaceTypes,
// filterByStops,
// filterByRoutes,
// filterByBikeRentalStations,
// filterByBikeParks,
// filterByCarParks,
// environment.getArgument("filterByInUse")
// );
// } catch (VertexNotFoundException e) {
// LOG.warn("findClosestPlacesByWalking failed with exception, returning empty list of places. " , e);
// places = Collections.emptyList();
// }
//
// places = convertQuaysToStopPlaces(placeTypes, places, environment.getArgument("multiModalMode")).stream().limit(orgMaxResults).collect(Collectors.toList());
// if (CollectionUtils.isEmpty(places)) {
// return new DefaultConnection<>(Collections.emptyList(), new DefaultPageInfo(null, null, false, false));
// }
// return new SimpleListConnection(places).get(environment);
// })
// .build())
// TODO OTP2 - FIX THIS, THIS IS A BUG
// List<String> privateCodes=environment.getArgument("privateCodes");
// TODO OTP2 - Use FeedScoped ID
// .filter(t -> CollectionUtils.isEmpty(privateCodes) || privateCodes.contains(t.getTripPrivateCode()))
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("carPark")
// .description("Get a single car park based on its id")
// .type(carParkType)
// .argument(GraphQLArgument.newArgument()
// .name("id")
// .type(new GraphQLNonNull(Scalars.GraphQLString))
// .build())
// .dataFetcher(environment -> index.graph.getService(CarParkService.class)
// .getCarParks()
// .stream()
// .filter(carPark -> carPark.id.equals(environment.getArgument("id")))
// .findFirst()
// .orElse(null))
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("carParks")
// .description("Get all car parks")
// .type(new GraphQLNonNull(new GraphQLList(carParkType)))
// .argument(GraphQLArgument.newArgument()
// .name("ids")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .dataFetcher(environment -> {
// if ((environment.getArgument("ids") instanceof List)) {
// Map<String, CarPark> carParks = index.graph.getService(CarParkService.class).getCarParkById();
// return ((List<String>) environment.getArgument("ids"))
// .stream()
// .map(carParks::get)
// .collect(Collectors.toList());
// }
// return new ArrayList<>(index.graph.getService(CarParkService.class).getCarParks());
// })
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("notices")
// .description("Get all notices")
// .type(new GraphQLNonNull(new GraphQLList(noticeType)))
// .dataFetcher(environment -> index.getNoticesByEntity().values())
// .build())
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("QueryType").field(tripFieldType).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlace").description("Get a single stopPlace based on its id)").type(stopPlaceType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(env -> StopPlaceType.fetchStopPlaceById(TransitIdMapper.mapIDToDomain(env.getArgument("id")), env)).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlaces").description("Get all stopPlaces").type(new GraphQLNonNull(new GraphQLList(stopPlaceType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(env -> {
if ((env.getArgument("ids") instanceof List)) {
return ((List<String>) env.getArgument("ids")).stream().map(TransitIdMapper::mapIDToDomain).map(id -> StopPlaceType.fetchStopPlaceById(id, env)).collect(Collectors.toList());
}
return new ArrayList<>(GqlUtil.getRoutingService(env).getStations());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlacesByBbox").description("Get all stop places within the specified bounding box").type(new GraphQLNonNull(new GraphQLList(stopPlaceType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("multiModalMode").type(EnumTypes.MULTI_MODAL_MODE).description("MultiModalMode for query. To control whether multi modal parent stop places, their mono modal children or both are included in the response." + " Does not affect mono modal stop places that do not belong to a multi modal stop place.").defaultValue("parent").build()).argument(GraphQLArgument.newArgument().name("filterByInUse").description("If true only stop places with at least one visiting line are included.").type(Scalars.GraphQLBoolean).defaultValue(Boolean.FALSE).build()).dataFetcher(env -> {
double minLat = env.getArgument("minimumLatitude");
double minLon = env.getArgument("minimumLongitude");
double maxLat = env.getArgument("maximumLatitude");
double maxLon = env.getArgument("maximumLongitude");
String authority = env.getArgument("authority");
boolean filterByInUse = TRUE.equals(env.getArgument("filterByInUse"));
String multiModalMode = env.getArgument("multiModalMode");
return StopPlaceType.fetchStopPlaces(minLat, minLon, maxLat, maxLon, authority, filterByInUse, multiModalMode, env);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quay").description("Get a single quay based on its id)").type(quayType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getStopForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quays").description("Get all quays").type(new GraphQLNonNull(new GraphQLList(quayType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("name").type(Scalars.GraphQLString).build()).dataFetcher(environment -> {
if ((environment.getArgument("ids") instanceof List)) {
if (environment.getArguments().entrySet().stream().filter(stringObjectEntry -> stringObjectEntry.getValue() != null).collect(Collectors.toList()).size() != 1) {
throw new IllegalArgumentException("Unable to combine other filters with ids");
}
RoutingService routingService = GqlUtil.getRoutingService(environment);
return ((List<String>) environment.getArgument("ids")).stream().map(id -> routingService.getStopForId(TransitIdMapper.mapIDToDomain(id))).collect(Collectors.toList());
}
if (environment.getArgument("name") == null) {
return GqlUtil.getRoutingService(environment).getAllStops();
}
// }
return emptyList();
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quaysByBbox").description("Get all quays within the specified bounding box").type(new GraphQLNonNull(new GraphQLList(quayType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("filterByInUse").description("If true only quays with at least one visiting line are included.").type(Scalars.GraphQLBoolean).defaultValue(Boolean.FALSE).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getStopsByBoundingBox(environment.getArgument("minimumLatitude"), environment.getArgument("minimumLongitude"), environment.getArgument("maximumLatitude"), environment.getArgument("maximumLongitude")).stream().filter(stop -> environment.getArgument("authority") == null || stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority"))).filter(stop -> {
boolean filterByInUse = TRUE.equals(environment.getArgument("filterByInUse"));
boolean inUse = !GqlUtil.getRoutingService(environment).getPatternsForStop(stop, true).isEmpty();
return !filterByInUse || inUse;
}).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quaysByRadius").description("Get all quays within the specified walking radius from a location. The returned type has two fields quay and distance").type(relay.connectionType("quayAtDistance", relay.edgeType("quayAtDistance", quayAtDistance, null, new ArrayList<>()), new ArrayList<>())).argument(GraphQLArgument.newArgument().name("latitude").description("Latitude of the location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("longitude").description("Longitude of the location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("radius").description("Radius via streets (in meters) to search for from the specified location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).arguments(relay.getConnectionFieldArguments()).dataFetcher(environment -> {
List<StopAtDistance> stops;
try {
stops = GqlUtil.getRoutingService(environment).findClosestStops(environment.getArgument("latitude"), environment.getArgument("longitude"), environment.getArgument("radius")).stream().filter(stopAtDistance -> environment.getArgument("authority") == null || stopAtDistance.stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority"))).sorted(Comparator.comparing(s -> s.distance)).collect(Collectors.toList());
} catch (RoutingValidationException e) {
LOG.warn("findClosestPlacesByWalking failed with exception, returning empty list of places. ", e);
stops = List.of();
}
if (CollectionUtils.isEmpty(stops)) {
return new DefaultConnection<>(Collections.emptyList(), new DefaultPageInfo(null, null, false, false));
}
return new SimpleListConnection<>(stops).get(environment);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authority").description("Get an authority by ID").type(authorityType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getAgencyForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authorities").description("Get all authorities").type(new GraphQLNonNull(new GraphQLList(authorityType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getAgencies());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("operator").description("Get a operator by ID").type(operatorType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getOperatorForId().get(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("operators").description("Get all operators").type(new GraphQLNonNull(new GraphQLList(operatorType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getAllOperators());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("line").description("Get a single line based on its id").type(lineType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLID)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getRouteForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("lines").description("Get all lines").type(new GraphQLNonNull(new GraphQLList(lineType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLID)).build()).argument(GraphQLArgument.newArgument().name("name").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("publicCode").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("publicCodes").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("transportModes").type(new GraphQLList(TRANSPORT_MODE)).build()).argument(GraphQLArgument.newArgument().name("authorities").description("Set of ids of authorities to fetch lines for.").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
if ((environment.getArgument("ids") instanceof List)) {
if (environment.getArguments().entrySet().stream().filter(it -> it.getValue() != null).count() != 1) {
throw new IllegalArgumentException("Unable to combine other filters with ids");
}
return ((List<String>) environment.getArgument("ids")).stream().map(id1 -> TransitIdMapper.mapIDToDomain(id1)).map(id -> {
return GqlUtil.getRoutingService(environment).getRouteForId(id);
}).collect(Collectors.toList());
}
Stream<Route> stream = GqlUtil.getRoutingService(environment).getAllRoutes().stream();
if (environment.getArgument("name") != null) {
stream = stream.filter(route -> route.getLongName() != null).filter(route -> route.getLongName().toLowerCase().startsWith(((String) environment.getArgument("name")).toLowerCase()));
}
if (environment.getArgument("publicCode") != null) {
stream = stream.filter(route -> route.getShortName() != null).filter(route -> route.getShortName().equals(environment.getArgument("publicCode")));
}
if (environment.getArgument("publicCodes") instanceof List) {
Set<String> publicCodes = Set.copyOf(environment.getArgument("publicCodes"));
stream = stream.filter(route -> route.getShortName() != null).filter(route -> publicCodes.contains(route.getShortName()));
}
if (environment.getArgument("transportModes") != null) {
Set<TraverseMode> modes = ((List<TraverseMode>) environment.getArgument("transportModes")).stream().filter(TraverseMode::isTransit).collect(Collectors.toSet());
// TODO OTP2 - FIX THIS, THIS IS A BUG
stream = stream.filter(route -> modes.contains(route.getMode()));
}
if ((environment.getArgument("authorities") instanceof Collection)) {
Collection<String> authorityIds = environment.getArgument("authorities");
stream = stream.filter(route -> route.getAgency() != null && authorityIds.contains(route.getAgency().getId().getId()));
}
return stream.collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourney").description("Get a single service journey based on its id").type(serviceJourneyType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getTripForId().get(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourneys").description("Get all service journeys").type(new GraphQLNonNull(new GraphQLList(serviceJourneyType))).argument(GraphQLArgument.newArgument().name("lines").description("Set of ids of lines to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLID)).build()).argument(GraphQLArgument.newArgument().name("privateCodes").description("Set of ids of private codes to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("activeDates").description("Set of ids of active dates to fetch serviceJourneys for.").type(new GraphQLList(gqlUtil.dateScalar)).build()).argument(GraphQLArgument.newArgument().name("authorities").description("Set of ids of authorities to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
List<FeedScopedId> lineIds = mapIDsToDomain(environment.getArgument("lines"));
// List<String> privateCodes=environment.getArgument("privateCodes");
List<Long> activeDates = environment.getArgument("activeDates");
// TODO OTP2 - Use FeedScoped ID
List<String> authorities = environment.getArgument("authorities");
return GqlUtil.getRoutingService(environment).getTripForId().values().stream().filter(t -> CollectionUtils.isEmpty(lineIds) || lineIds.contains(t.getRoute().getId())).filter(t -> CollectionUtils.isEmpty(authorities) || authorities.contains(t.getRoute().getAgency().getId().getId())).filter(t -> {
return CollectionUtils.isEmpty(activeDates) || GqlUtil.getRoutingService(environment).getCalendarService().getServiceDatesForServiceId(t.getServiceId()).stream().anyMatch(sd -> activeDates.contains(gqlUtil.serviceDateMapper.serviceDateToSecondsSinceEpoch(sd)));
}).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStations").description("Get all bike rental stations").argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).type(new GraphQLNonNull(new GraphQLList(bikeRentalStationType))).dataFetcher(environment -> {
Collection<BikeRentalStation> all = new ArrayList<>(GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeRentalStations());
List<String> filterByIds = environment.getArgument("ids");
if (!CollectionUtils.isEmpty(filterByIds)) {
return all.stream().filter(station -> filterByIds.contains(station.id)).collect(Collectors.toList());
}
return all;
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStation").description("Get all bike rental stations").type(bikeRentalStationType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeRentalStations().stream().filter(bikeRentalStation -> bikeRentalStation.id.equals(environment.getArgument("id"))).findFirst().orElse(null);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStationsByBbox").description("Get all bike rental stations within the specified bounding box. NOT IMPLEMENTED").type(new GraphQLNonNull(new GraphQLList(bikeRentalStationType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(Scalars.GraphQLFloat).build()).dataFetcher(environment -> Collections.emptyList()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikePark").description("Get a single bike park based on its id").type(bikeParkType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeParks().stream().filter(bikePark -> bikePark.id.equals(environment.getArgument("id"))).findFirst().orElse(null);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeParks").description("Get all bike parks").type(new GraphQLNonNull(new GraphQLList(bikeParkType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeParks());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("routingParameters").description("Get default routing parameters.").type(this.routing.graphQLType).dataFetcher(environment -> routing.request).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("situations").description("Get all active situations.").type(new GraphQLNonNull(new GraphQLList(ptSituationElementType))).argument(GraphQLArgument.newArgument().name("authorities").description("Filter by reporting authorities.").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("severities").description("Filter by severity.").type(new GraphQLList(EnumTypes.SEVERITY)).build()).dataFetcher(environment -> {
Collection<TransitAlert> alerts = GqlUtil.getRoutingService(environment).getTransitAlertService().getAllAlerts();
if ((environment.getArgument("authorities") instanceof List)) {
List<String> authorities = environment.getArgument("authorities");
alerts = alerts.stream().filter(alert -> authorities.contains(alert.getFeedId())).collect(Collectors.toSet());
}
if ((environment.getArgument("severities") instanceof List)) {
List<String> severities = environment.getArgument("severities");
alerts = alerts.stream().filter(alert -> severities.contains(alert.severity)).collect(Collectors.toSet());
}
return alerts;
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serverInfo").description("Get OTP server information").type(new GraphQLNonNull(serverInfoType)).dataFetcher(e -> MavenVersion.VERSION).build()).build();
Set<GraphQLType> dictionary = new HashSet<>();
dictionary.add(placeInterface);
dictionary.add(timetabledPassingTime);
dictionary.add(Relay.pageInfoType);
return GraphQLSchema.newSchema().query(queryType).build(dictionary);
}
use of graphql.schema.GraphQLNamedOutputType in project graphql-java by graphql-java.
the class SchemaUtil method groupImplementationsForInterfacesAndObjects.
public Map<String, List<GraphQLImplementingType>> groupImplementationsForInterfacesAndObjects(GraphQLSchema schema) {
Map<String, List<GraphQLImplementingType>> result = new LinkedHashMap<>();
for (GraphQLType type : schema.getAllTypesAsList()) {
if (type instanceof GraphQLImplementingType) {
List<GraphQLNamedOutputType> interfaces = ((GraphQLImplementingType) type).getInterfaces();
for (GraphQLNamedOutputType interfaceType : interfaces) {
List<GraphQLImplementingType> myGroup = result.computeIfAbsent(interfaceType.getName(), k -> new ArrayList<>());
myGroup.add((GraphQLImplementingType) type);
}
}
}
return ImmutableMap.copyOf(new TreeMap<>(result));
}
use of graphql.schema.GraphQLNamedOutputType in project graphql-java by graphql-java.
the class Anonymizer method getSameFieldsImpl.
private static void getSameFieldsImpl(String fieldName, String curObjectOrInterface, Map<String, List<GraphQLImplementingType>> interfaceToImplementations, GraphQLSchema schema, Set<String> alreadyChecked, Set<GraphQLFieldDefinition> result) {
if (alreadyChecked.contains(curObjectOrInterface)) {
return;
}
alreadyChecked.add(curObjectOrInterface);
// "up": get all Interfaces
GraphQLImplementingType type = (GraphQLImplementingType) schema.getType(curObjectOrInterface);
List<GraphQLNamedOutputType> interfaces = type.getInterfaces();
getMatchingFieldDefinitions(fieldName, interfaces, result);
for (GraphQLNamedOutputType interfaze : interfaces) {
getSameFieldsImpl(fieldName, interfaze.getName(), interfaceToImplementations, schema, alreadyChecked, result);
}
// "down": get all Object or Interfaces
List<GraphQLImplementingType> implementations = interfaceToImplementations.get(curObjectOrInterface);
if (implementations == null) {
return;
}
getMatchingFieldDefinitions(fieldName, implementations, result);
for (GraphQLImplementingType implementingType : implementations) {
getSameFieldsImpl(fieldName, implementingType.getName(), interfaceToImplementations, schema, alreadyChecked, result);
}
}
use of graphql.schema.GraphQLNamedOutputType in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherWiringFactoryTest method getTypeMock.
private GraphQLNamedOutputType getTypeMock(String typeName) {
GraphQLNamedOutputType typeMock = mock(GraphQLNamedOutputType.class);
lenient().when(typeMock.getName()).thenReturn(typeName);
return typeMock;
}
use of graphql.schema.GraphQLNamedOutputType in project graphql-java by graphql-java.
the class SchemaUsage method isReferencedImpl.
private boolean isReferencedImpl(GraphQLSchema schema, String elementName, Set<String> pathSoFar) {
if (pathSoFar.contains(elementName)) {
// circular reference to that element
return false;
}
pathSoFar.add(elementName);
if (ScalarInfo.isGraphqlSpecifiedScalar(elementName)) {
return true;
}
GraphQLDirective directive = schema.getDirective(elementName);
if (directive != null) {
String directiveName = directive.getName();
if (DirectiveInfo.isGraphqlSpecifiedDirective(directiveName)) {
return true;
}
if (isNamedElementReferenced(schema, directiveName, pathSoFar)) {
return true;
}
}
GraphQLNamedType type = schema.getTypeAs(elementName);
if (type == null) {
return false;
}
if (Introspection.isIntrospectionTypes(type)) {
return true;
}
if (type == schema.getQueryType()) {
return true;
}
if (type == schema.getMutationType()) {
return true;
}
if (type == schema.getSubscriptionType()) {
return true;
}
if (isNamedElementReferenced(schema, elementName, pathSoFar)) {
return true;
}
if (type instanceof GraphQLInterfaceType) {
Set<String> implementors = interfaceImplementors.getOrDefault(type.getName(), emptySet());
for (String implementor : implementors) {
if (isReferencedImpl(schema, implementor, pathSoFar)) {
return true;
}
}
}
if (type instanceof GraphQLObjectType) {
List<GraphQLNamedOutputType> interfaces = ((GraphQLObjectType) type).getInterfaces();
for (GraphQLNamedOutputType memberInterface : interfaces) {
Set<String> implementors = interfaceImplementors.getOrDefault(memberInterface.getName(), emptySet());
for (String implementor : implementors) {
if (isReferencedImpl(schema, implementor, pathSoFar)) {
return true;
}
}
}
}
return false;
}
Aggregations