-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql): allow fetching of the priority of a validation error type
- Loading branch information
1 parent
1d1ae24
commit 46c2b8e
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/conveyal/gtfs/graphql/fetchers/ErrorPriorityFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters