Skip to content

Conversation

magicmark
Copy link
Collaborator

@magicmark magicmark commented Feb 25, 2020

Fixes #1

Support a new isResponseDictionary option in the config.

See the tests for an an example of this in action, but tl;dr:

Example

Resource Response
A dict 😱 ! We couldn't deal with this before:

{
    "2": {
        "foo_id": 2,
        "foo_value": "world"
    },
    "1": {
        "foo_id": 1,
        "foo_value": "hello"
    },
    "3": {
        "foo_id": 3,
        "foo_value": "!"
    }
}

Config:

foo:
    isBatchResource: true,
    docsLink: 'example.com/docs/foos',
    batchKey: 'foo_ids',
    newKey: 'foo_id',
    isResponseDictionary: true,

Dataloader call:

const results = await loaders.foo.loadMany([
  { foo_id: 1 },
  { foo_id: 2 },
  { foo_id: 3 },
]);

Response:

[
    {
        "foo_id": 1,
        "foo_value": "hello"
    },
    {
        "foo_id": 2,
        "foo_value": "world"
    },
    {
        "foo_id": 3,
        "foo_value": "!"
    }
]

Thanks @jack-guy for the internal work to drive this!

@ryanruanwork
Copy link
Contributor

shipIt!
@magicmark could you give me access?

@magicmark magicmark merged commit bcb4b5f into master Mar 4, 2020
@magicmark magicmark deleted the add_isResponseDictionary_1 branch March 4, 2020 19:45
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.

Support endpoints where items are nested by ID
2 participants