-
Notifications
You must be signed in to change notification settings - Fork 122
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
Feature: API for providing a path-builder function #69
Comments
I like the idea, but wouldn't it be more appropriate to create a query builder instead of a path builder? In this way we could use existing query builders as a parameter and we keep the path separated from the query string formatting function. Modified code would look like this: const query = gql`
query FilterItems(
$priceMin: Int
$priceMax: Int
$queryBuilder: any
) {
filterItems(priceMin: $priceMin, priceMax: $priceMax)
@rest(type: "Item", path: "items", queryBuilder: $queryBuilder) {
id
name
price
}
} import queryString from 'query-string';
client.query({
query,
variables: {
priceMin: 5,
priceMax: 20,
queryBuilder: queryString.stringify
}
}); Another (small) remark is that we should exclude our "builder function" out of the incoming |
@jslowack That assumes that the REST API you're working is structured cleanly to take parameters in the Query string. A |
pathBuilder is a user provided function via a graphql variable to build up the path string. A use case it enables is having one or more optional query string parameters e.g: "/items/filter?minPrice=5&maxPrice=20" Here minPrice and maxPrice could be omitted See proposal in apollographql#69 and the problem it solves in apollographql#67
@HeyHugo, remember to use encodeURIComponent in your example code/unit test! (We want to be showing best practices in our examples :) ) |
@jslowack Thinking more about what you were saying, would you mind elaborating about "existing query builders"? I don't know what you're referring to, so I don't know what reuse there would be valuable. Thanks! |
Good idea @fbartho, thinking bout it maybe we'd want to always run For the default |
Ah disregard my previous comment, I was mixing up If anything we would instead use |
@fbartho for example https://github.com/sindresorhus/query-string. I agree that a pathBuilder is more generic. I personally just don't like the idea of a graphQL query where the path (or endpoint) is generic..
True! With this in mind, it makes more sense to create a path builder. |
pathBuilder is a user provided function via a graphql variable to build up the path string. A use case it enables is having one or more optional query string parameters e.g: "/items/filter?minPrice=5&maxPrice=20" Here minPrice and maxPrice could be omitted See proposal in apollographql#69 and the problem it solves in apollographql#67
pathBuilder is a user provided function via a graphql variable to build up the path string. A use case it enables is having one or more optional query string parameters e.g: "/items/filter?minPrice=5&maxPrice=20" Here minPrice and maxPrice could be omitted See proposal in apollographql#69 and the problem it solves in apollographql#67
pathBuilder is a user provided function via a graphql variable to build up the path string. A use case it enables is having one or more optional query string parameters e.g: "/items/filter?minPrice=5&maxPrice=20" Here minPrice and maxPrice could be omitted See proposal in apollographql#69 and the problem it solves in apollographql#67
@HeyHugo -- I thought about that, and I think |
Implemented via #70 ! |
For usecases like #67 where you need to handle query string parameters that are optional you can't right now.
I've looked a bit at how
bodyBuilder
andbodyKey
are used to allow custom body handling.I propose that an optional argument of type function is added to the rest-directive
pathBuilder
that if set is used to build the path string. The function would take the variables object as input.We can keep the current
path
parameter as is. Only if pathBuilder is provided it overrides.Here is an example using the
pathBuilder
to handle query strings arg:I can try to make a PR if you like the idea.
The text was updated successfully, but these errors were encountered: