Skip to content

Conversation

@avelosa
Copy link

@avelosa avelosa commented Mar 21, 2025

Tried to implement supporting the include functionality that is traditionally specified as a query parameter. The include feature is defined here.
Since there are multiple operations this implementation lets the api user specify a meta object at the top level of each individual operation data. In the meta object the api user can set the include field that expects a list of relationship names.

Example Request Data:

{
  "atomic:operations": [
    {
      "op": "add",
      "data": {
        "type": "Book",
        "attributes": {
          "title": "Meditations"
        },
        "relationships": {
          "author": {
             "data": {
               "id": "1",
               "type": "Author"
             }
          }
        }
      },
      "meta": {
        "include": ["author"]
      }
    }
  ]
}

Example Response Data:

{
  "atomic:results": [
    {
      "data": {
        "type": "Book",
        "id": "1",
        "attributes": {
          "title": "Meditations"
        },
        "relationships": {
          "author": {
             "data": {
               "id": "1",
               "type": "Author"
             }
          }
        }
      }
    },
    "included": [
      {
        "data": {
          "id": "1",
          "type": "Author",
          "attributes": {
            "first_name": "Marcus",
            "last_name": "Aurelius"
          }
        }
      }     
    ]
  ]
}

Each operation can use the include parameter if desired. The meta field is of course optional.

Also adds unit tests for the view and parser.

@avelosa avelosa force-pushed the add-include-support branch from 16c2929 to 310b1d2 Compare March 21, 2025 23:37
andrewbird2 added a commit to affinda/drf-json-api-atomic-operations that referenced this pull request Nov 25, 2025
This merges the include support from upstream PR jokiefer#11, allowing each atomic
operation to specify its own `meta.include` array to include related resources
in the response.

Key changes:
- parsers.py: Add parse_operation_metadata() to extract meta.include from operations
- renderers.py: Add extract_included() to use per-operation includes instead of query params
- serializers.py: Add AtomicOperationIncludedResourcesValidationMixin for include validation
- views.py: Wrap serializers with validation mixin and pass operation context

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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