Skip to content

Commit

Permalink
feat(graphql): allow fetching of the priority of a validation error type
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Jan 22, 2020
1 parent 1d1ae24 commit 46c2b8e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.conveyal.gtfs.graphql;

import com.conveyal.gtfs.graphql.fetchers.ErrorCountFetcher;
import com.conveyal.gtfs.graphql.fetchers.ErrorPriorityFetcher;
import com.conveyal.gtfs.graphql.fetchers.FeedFetcher;
import com.conveyal.gtfs.graphql.fetchers.JDBCFetcher;
import com.conveyal.gtfs.graphql.fetchers.MapFetcher;
Expand Down Expand Up @@ -421,6 +422,7 @@ public class GraphQLGtfsSchema {
.field(MapFetcher.field("entity_id"))
.field(MapFetcher.field("entity_sequence", GraphQLInt))
.field(MapFetcher.field("bad_value"))
.field(ErrorPriorityFetcher.field("error_type_priority"))
.build();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.conveyal.gtfs.graphql.fetchers;

import com.conveyal.gtfs.error.NewGTFSErrorType;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.GraphQLFieldDefinition;

import java.util.Map;

import static graphql.Scalars.GraphQLString;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;

/**
* A fetcher that is specifically used for looking up and returning the priority of a specific error_type
*/
public class ErrorPriorityFetcher implements DataFetcher {
public static GraphQLFieldDefinition field(String name) {
return newFieldDefinition()
.name(name)
.type(GraphQLString)
.dataFetcher(new ErrorPriorityFetcher())
.build();
}

@Override
public Object get(DataFetchingEnvironment dataFetchingEnvironment) {
Object source = dataFetchingEnvironment.getSource();
String errorType = (String) ((Map<String, Object>)source).get("error_type");
return NewGTFSErrorType.valueOf(errorType).priority;
}
}
1 change: 1 addition & 0 deletions src/test/resources/graphql/feedErrors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ query($namespace: String) {
bad_value
error_id
error_type
error_type_priority
entity_id
entity_sequence
entity_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"entity_type" : "Agency",
"error_id" : 0,
"error_type" : "MISSING_FIELD",
"error_type_priority" : "MEDIUM",
"line_number" : 2
}, {
"bad_value" : "route 1",
Expand All @@ -16,6 +17,7 @@
"entity_type" : "Route",
"error_id" : 1,
"error_type" : "ROUTE_LONG_NAME_CONTAINS_SHORT_NAME",
"error_type_priority" : "LOW",
"line_number" : 2
}, {
"bad_value" : null,
Expand All @@ -24,6 +26,7 @@
"entity_type" : null,
"error_id" : 2,
"error_type" : "FEED_TRAVEL_TIMES_ROUNDED",
"error_type_priority" : "LOW",
"line_number" : null
}, {
"bad_value" : "1234567",
Expand All @@ -32,6 +35,7 @@
"entity_type" : "Stop",
"error_id" : 3,
"error_type" : "STOP_UNUSED",
"error_type_priority" : "MEDIUM",
"line_number" : 6
}, {
"bad_value" : "20170916",
Expand All @@ -40,6 +44,7 @@
"entity_type" : null,
"error_id" : 4,
"error_type" : "DATE_NO_SERVICE",
"error_type_priority" : "MEDIUM",
"line_number" : null
} ],
"feed_version" : "1.0"
Expand Down

0 comments on commit 46c2b8e

Please sign in to comment.