Skip to content

Commit

Permalink
Docs: add docs for resolving multiple path parameters (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash authored Oct 6, 2024
1 parent ca9a869 commit b97a45c
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ rest_api.config_setup.register_auth("custom_auth", CustomAuth)

### Define resource relationships

When you have a resource that depends on another resource, you can define the relationship using the `resolve` configuration. With it, you link a path parameter in the child resource to a field in the parent resource's data.
When you have a resource that depends on another resource, you can define the relationship using the `resolve` configuration. This allows you to link one or more path parameters in the child resource to fields in the parent resource's data.

In the GitHub example, the `issue_comments` resource depends on the `issues` resource. The `issue_number` parameter in the `issue_comments` endpoint configuration is resolved from the `number` field of the `issues` resource:

Expand Down Expand Up @@ -638,6 +638,54 @@ The `field` value can be specified as a [JSONPath](https://github.com/h2non/json

Under the hood, dlt handles this by using a [transformer resource](../../../general-usage/resource.md#process-resources-with-dlttransformer).

#### Resolving multiple path parameters from a parent resource

When a child resource depends on multiple fields from a single parent resource, you can define multiple `resolve` parameters in the endpoint configuration. For example:

```py
{
"resources": [
"groups",
{
"name": "users",
"endpoint": {
"path": "groups/{group_id}/users",
"params": {
"group_id": {
"type": "resolve",
"resource": "groups",
"field": "id",
},
},
},
},
{
"name": "user_details",
"endpoint": {
"path": "groups/{group_id}/users/{user_id}/details",
"params": {
"group_id": {
"type": "resolve",
"resource": "users",
"field": "group_id",
},
"user_id": {
"type": "resolve",
"resource": "users",
"field": "id",
},
},
},
},
],
}
```

In the configuration above:

- The `users` resource depends on the `groups` resource, resolving the `group_id` parameter from the `id` field in `groups`.
- The `user_details` resource depends on the `users` resource, resolving both `group_id` and `user_id` parameters from fields in `users`.

#### Include fields from the parent resource

You can include data from the parent resource in the child resource by using the `include_from_parent` field in the resource configuration. For example:
Expand Down

0 comments on commit b97a45c

Please sign in to comment.