Comments (2)
from apollo-link-rest.
I've looked through the pathBuilder
PR and think a query string builder would still be beneficial. I'm getting into writing all my queries and ran across the thought of having to provide the pathBuilder
function every time. It doesn't seem very DRY (which may not be your goal).
On the Apollo docs page, it mentions a params
option for the @rest
directive:
const QUERY = gql`
query RestData($email: String!) {
users @rest(path: '/users/email/:email', params: { email: $email }, method: 'GET', type: 'User')
I think this is outdated as I don't see anything in the code that would support this unless I'm missing it, but something similar for the query string would be nice.
query RestData($email: String!) {
users @rest(type: "[User]", path: '/users/email', queryParams: {email: $email})
}
This would automatically create a query string based on the queryParams and append it to the path. I think I would actually prefer this in the case of multiple @rest in the same query that may not use every param such as:
query RestData($userId: ID!, $startDate: String!, $endDate: String!) {
user @rest(type: "User", path: '/users/:userId') {
id
name
reports @rest(type: "[UserReport]", path: '/users/reports', queryParams: {startDate: $startDate, endDate: $endDate})
}
}
If I understand correctly, this would be the equivalent using pathBuilder
let getPathBuilder = url => params => `${url}?${queryString.stringify(params)}`
const query = gql`
query RestDate($userId: ID!, $startDate: String!, $endDate: String!, $userPath: any, $reportsPath: any) {
user (id: $id) @rest(type: "User", pathBuilder: $userPath) {
id
name
reports (startDate: $startDate, endDate: $endDate) @rest(type: "[UserReport]", pathBuilder: $reportsPath)
}
`
client.query({
query,
variables: {
id: someId,
startDate: "05-01-2018",
endDate: "05-31-2018",
userPath: getPathBuilder("/user"),
reportsPath: getPathBuilder("/user/reports")
}
});
from apollo-link-rest.
Related Issues (20)
- Fix typo when defining type for bodySerializer on 'bodySerializer' section
- RestLink causes network calls to be executed much later HOT 4
- Is this repo obsolete? HOT 3
- How to batch operations with apollo-link-rest? HOT 4
- Latest possible (0.8.0) release is still in beta with no active changes HOT 5
- TypeError: Cannot read properties of undefined (reading 'selections') HOT 4
- Questions about apollo-link-rest production status HOT 8
- `graphql-anywhere` is unmaintained; how does this impact `apollo-link-rest`? HOT 17
- Use exported variable in POST request body HOT 7
- Can i use DELETE method with request body? HOT 1
- Conditionally skip REST calls HOT 8
- Apollo Link Rest - MockProvider HOT 1
- Apollo return same data even datatype and url is changed through variables HOT 1
- **Urgent**: Lost Maintainer/Collaborator Access HOT 3
- How to limit the number of items of nested array? HOT 2
- Unable to access context value in the graphql query
- Feature Proposal - RestLink chains HOT 1
- Dependency Dashboard
- data and error fields in useQuery hook empty.
- Can only the remaining uncached links be retrieved? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-link-rest.