Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTDataSource - POST body as array #2196

Closed
bartverbruggen opened this issue Jan 18, 2019 · 2 comments
Closed

RESTDataSource - POST body as array #2196

bartverbruggen opened this issue Jan 18, 2019 · 2 comments

Comments

@bartverbruggen
Copy link
Contributor

There seems to be a problem when trying to send an array as body with the RESTDataSource post call.

When trying to execute following function, the endpoint receives an empty body in the request.

async addMultipleItems({ input = [{...}, {...}, ...] }: any) {
  return this.post('/items', input)
}

The res.body of the endpoint should contain [{...}, {...}, ...] but contains {}.

Any help?

@bartverbruggen
Copy link
Contributor Author

I've temporary fixed this by setting the content type header in de post:

  async addMultipleItems({ input = [{...}, {...}, ...] }: any) {
    return this.post('/items', JSON.stringify(input), {
      headers: {
        'Content-Type': 'application/json',
      },
    })
  }

But if this is done in RESTDataSource.ts for objects, I think the same should be true for arrays.

abernix added a commit that referenced this issue Feb 5, 2019
Fixes issue introduced in #1125 and logged in #2186 and #2196.

Arrays are valid JSON per spec: https://tools.ietf.org/html/rfc7159
@trevorblades
Copy link
Contributor

This appears to be resolved by #2219

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants