-
Notifications
You must be signed in to change notification settings - Fork 32
Conversation
dea26a6
to
72a9a0a
Compare
@jaydenseric if you get a chance, could you look a this PR? I want to provide you the ability to create an upload client and include it as a lerna package, so that your upload client can take easy advantage of integration test. Do you see a way forward if we pull this in? I envision that your upload fetch package could export either a createApolloFetchUpload, an import {
createApolloFetch,
createDefaultOptions,
}
export function constructUploadOptions(requestOrRequests, options) {
if( isFileUpload(requestOrRequests, options)) {
return {
...options,
body: extract-files(requestOrRequests),
}
} else {
return constructDefaultOptions(requestOrRequests, options);
}
}
export createApolloFetchUpload(params) {
return createApolloFetch({
...params,
constructOptions: createUploadOptions,
})
}
const apolloFetchUpload = createApolloFetchUpload();
export apolloFetchUpload; Please let me know if you need more hooks in In the whirlwind, I never got to mention that your |
Thanks 😊 This approach should work; I'll try to have the packages ready in the next few days. Working on them will be a bit easier after this PR is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks legit! A few requests for improvements.
README.md
Outdated
@@ -1,9 +1,12 @@ | |||
# apollo-fetch [![npm version](https://badge.fury.io/js/apollo-fetch.svg)](https://badge.fury.io/js/apollo-fetch) [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](http://www.apollostack.com/#slack) | |||
|
|||
|
|||
`apollo-fetch` is a lightweight client for GraphQL requests that supports middleware and afterware that modify requests and responses. | |||
`apollo-fetch` is a lightweight client for single and batched GraphQL requests that supports middleware and afterware that modify requests and responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this dilutes the description. Batching is a feature, no need to mention it in the tagline.
README.md
Outdated
These transformations can be useful for servers that have different formatting for batches or other extra capabilities. | ||
|
||
```js | ||
const constructOptions = (requestOrRequests, init) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment here about what requestOrRequests
means.
README.md
Outdated
use: (middlewares: MiddlewareInterface) => ApolloFetch; | ||
useAfter: (afterwares: AfterwareInterface) => ApolloFetch; | ||
batchUse: (middlewares: BatchMiddlewareInterface) => ApolloFetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is BatchMiddlewareInterface
defined anywhere?
docs/batch.md
Outdated
|
||
### Batch Formatting | ||
|
||
Since GraphQL does not include batched requests in the formal spec, `apollo-fetch` creates a request that is compatible with [`apollo-server`](https://github.com/apollographql/apollo-server). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GraphQL does not include batched requests in the formal spec
No kind of request is mentioned in the spec. So no need to make this exception here.
Maybe say "not all GraphQL servers support batching out of the box" or something.
docs/monorepo.md
Outdated
Copying the `apollo-fetch` folder will provide a good starting point for revision and additions. | ||
Including new fetch's in the lerna project, will allow packages have integration tests with any core changes. | ||
|
||
The typescript specific functionality is encapsulated within a package, so ou are also able to create a fetch with javascript to include here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.. I think we'd really like to use the same language for everything in the same repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ou -> you
docs/monorepo.md
Outdated
|
||
## Creating a new fetch | ||
|
||
If you are creating a new fetch and would like to included in the lerna repository, the easiest place to start is copying the `apollo-fetch` folder in `<repository root>/packages`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would people want it in this repository? For testing reasons? I feel like this should include a note about what should actually be in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stubailo I think this is intended for other contributors to PR and add in new packages if the need arises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanshauser a couple questions but otherwise this looks great!
README.md
Outdated
|
||
By default `apollo-fetch` uses `isomorphic-fetch`, but you have the option of using a custom fetch function. | ||
Additionally, `apollo-fetch` allows specification of how GraphQL requests are included in fetch options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is awkward? I'm not sure what it is explaining
README.md
Outdated
const apolloFetch = createApolloFetch({ constructOptions }); | ||
|
||
//simplified usage inside apolloFetch | ||
fetch(uri, constructOptions(request, options)) //options are result of middleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this section, I think it could be helpful to include (not inline) the type definitions of request
and options
so developers can know what will be present when creating their own functions
@@ -261,21 +283,27 @@ createApolloFetch(options: FetchOptions): ApolloFetch | |||
FetchOptions { | |||
uri?: string; | |||
customFetch?: (request: RequestInfo, init: RequestInit) => Promise<Response>; | |||
constructOptions?: (requestOrRequests: GraphQLRequest | GraphQLRequest[], options: RequestInit) => RequestInit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the previous comment can just link to this?
docs/monorepo.md
Outdated
|
||
## Creating a new fetch | ||
|
||
If you are creating a new fetch and would like to included in the lerna repository, the easiest place to start is copying the `apollo-fetch` folder in `<repository root>/packages`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stubailo I think this is intended for other contributors to PR and add in new packages if the need arises
}); | ||
}; | ||
|
||
const apolloFetch: ApolloFetch = <ApolloFetch>Object.assign( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanshauser what is the purpose of the Object assign here?
@evanshauser I've added #11 as well to add some root level npm shortcuts and formatting. |
apollo-fetch is now in the lerna ecosystem and supports batching, while still being compatible with the previous single request API.