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

Allow POST/PUT/etc methods in Query operations to utilize a body. #173

Merged
merged 4 commits into from
Nov 26, 2018

Conversation

nderscore
Copy link
Contributor

@nderscore nderscore commented Nov 14, 2018

  • Remove restriction that only allows request bodies to be built for Mutation operations.

This PR resolves #154.

Since v0.5.0, POST and other "Mutation"-y HTTP methods (PUT, PATCH, etc) are now permitted in Query operations.

Currently, when a query is defined using the @rest directive to wrap a POST call which includes a body (eg: input argument), the body is silently ignored, despite the request being made as otherwise expected.

This is because a restriction is still in place which prevents them having a body added to the request unless they are part of a Mutation operation. If we're going to allow a POST request to be made from a Query, it makes sense to include support for a body, since in most cases, these requests need them. This PR relaxes that restriction, instead relying solely on the HTTP method to determine whether we should attempt to build a body for the request.

@ghost ghost added the enhancement label Nov 14, 2018
@codecov-io
Copy link

codecov-io commented Nov 15, 2018

Codecov Report

Merging #173 into master will increase coverage by 0.25%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #173      +/-   ##
==========================================
+ Coverage   92.65%   92.91%   +0.25%     
==========================================
  Files           2        2              
  Lines         395      395              
  Branches      117      116       -1     
==========================================
+ Hits          366      367       +1     
+ Misses         27       26       -1     
  Partials        2        2
Impacted Files Coverage Δ
src/restLink.ts 92.7% <100%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48af562...30fcb92. Read the comment docs.

@fbartho
Copy link
Collaborator

fbartho commented Nov 15, 2018

@nderscore would you mind adding some unit-tests to make sure we don't break this in the future? Thanks!

@nderscore
Copy link
Contributor Author

@fbartho No problem. I added a test to cover this usage.

I also added a test for the error state for when no body input is provided, since I touched it and it was missing from coverage. Turns out, it was unreachable code when no args are passed to the query, so I fixed that as well. 😄

Copy link

@icebox icebox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. LGTM

@Falieson
Copy link

This PR fixes my issue. I guess until it gets released I'll throw it on npm under @tgrx/apollo-link-rest@0.6.1

Copy link
Collaborator

@fbartho fbartho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo!

@fbartho fbartho merged commit 77f7b38 into apollographql:master Nov 26, 2018
@nderscore
Copy link
Contributor Author

Thanks @fbartho

@fbartho
Copy link
Collaborator

fbartho commented Dec 14, 2018

Release Shipped:
https://github.com/apollographql/apollo-link-rest/releases/tag/v0.7.0

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

Successfully merging this pull request may close these issues.

query with JSON body with POST method
6 participants