Skip to main content

πŸ” 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:

  1. Define the GraphQL query
    Create a new query file in:
    app/graphql/queries/problem_protocol/

  2. Register the query in the schema
    Add it to the ProblemProtocolQueryType.

  3. Update the GraphQL schema
    Run:

    bundle exec rake graphql:dump_schema
  4. Add a handler in ProblemProtocolFetcher Implement a method that handles the new query key.

  5. Write tests Add unit specs for:

    • The new GraphQL query
    • The corresponding fetcher method