π Problem Protocol Fetcher
π Purposeβ
The ProblemProtocolFetcher
class serves as the bridge between the protocol evaluator and Arcβs data. It is responsible for:
- Fetching all necessary data for the evaluation of protocol transitions.
- Querying the
ProblemProtocolApiSchema
GraphQL API. - Retrieving information about interventions, form responses, and other related data for a given problem goal.
- Validating query parameters before execution.
- Parsing API responses into the format expected by the evaluator.
β¨ Key Featuresβ
-
GraphQL Queries
Executes GraphQL queries to retrieve relevant data. -
Parameter Validation
Ensures the correct parameters are passed to each fetcher. -
Response Parsing
Transforms raw API data into evaluator-friendly formats (e.g., converting strings to arrays, numbers, etc.).
π¦ Supported Fetchersβ
To see the full list, refer to the fetch implementation here.
Current supported fetchers include:
avg_most_recent_n_form_scores
most_recent_completed_intervention
most_recent_form_question_response
most_recent_form_score
most_recent_n_form_scores
most_recent_form_results_report_value
housing_status
π§© Expected Type Parsingβ
In some cases, the API returns values in a format that doesnβt match what the evaluator expects. For example:
A form question response might return a string, but the evaluator expects an array.
In these situations, the fetcher is responsible for parsing the result into the correct type before returing it to the evaluator.
The list of fetchers that support type parsing can be found in the
QUERIES_WITH_SUPPORTED_EXPECTED_TYPE
constant.
π Creating a New Fetcherβ
When adding a new fetcher, follow these steps:
-
Define the GraphQL query
Create a new query file in:
app/graphql/queries/problem_protocol/
-
Register the query in the schema
Add it to theProblemProtocolQueryType
. -
Update the GraphQL schema
Run:bundle exec rake graphql:dump_schema
-
Add a handler in ProblemProtocolFetcher Implement a method that handles the new query key.
-
Write tests Add unit specs for:
- The new GraphQL query
- The corresponding fetcher method