Skip to content

Conversation

@filiperochalopes
Copy link

Summary

This PR introduces a new GraphQL API endpoint to the OCL API, enabling efficient searching and filtering of concepts within sources. The implementation leverages Elasticsearch for fast text-based queries while providing a robust fallback to database searches.

Changes

• New Django App: Added core/graphql/ with complete GraphQL schema and resolvers
• GraphQL Schema: Implemented conceptsFromSource query supporting:
• Fetching concepts by specific IDs with optional pagination
• Text-based search with Elasticsearch integration
• Automatic fallback to database search when Elasticsearch is unavailable
• Version resolution for sources (HEAD or specific versions)
• Mapping relationships included in responses
• Dependencies: Added Strawberry GraphQL libraries (strawberry-graphql, strawberry-graphql-django)
• URL Integration: Added GraphQL endpoint at /graphql/ with GraphiQL interface enabled
• Testing: Comprehensive test suite covering pagination, search ordering, error handling, and fallback
scenarios
• Infrastructure: Updated Docker Compose configuration and added documentation

Technical Details

• Uses async resolvers for optimal performance
• Implements custom ordering based on Elasticsearch relevance scores
• Includes proper error handling and GraphQL validation
• Follows existing codebase patterns for source/version resolution and data serialization
• Maintains compatibility with existing REST API endpoints

Verification Steps

  1. Start the API with docker compose up
  2. Access GraphiQL (Playground) at http://localhost:8000/graphql/
  3. Test queries like:
query {
  conceptsFromSource(org: "CIEL", source: "CIEL", query: "hypertension") {
    totalCount
    results {
      conceptId
      display
      mappings { mapType toCode }
    }
  }
}
  1. Run tests: docker compose run --rm api python manage.py test core.graphql.tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant