Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Add lerna support and batched requests #10

Merged
merged 7 commits into from
Jul 25, 2017
Merged

Add lerna support and batched requests #10

merged 7 commits into from
Jul 25, 2017

Conversation

evans
Copy link
Contributor

@evans evans commented Jul 22, 2017

apollo-fetch is now in the lerna ecosystem and supports batching, while still being compatible with the previous single request API.

  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change

@evans evans force-pushed the batch-lerna branch 4 times, most recently from dea26a6 to 72a9a0a Compare July 23, 2017 22:22
@evans evans changed the title Add lerna support and batching Add lerna support and batched requests Jul 24, 2017
@evans
Copy link
Contributor Author

evans commented Jul 24, 2017

@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 ApolloFetch with upload capabilities, or a createUploadOptions function. Something that might look like this:

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 ApolloFetch or anything in the PR is unclear.

In the whirlwind, I never got to mention that your extract-files package looks great!

@jaydenseric
Copy link
Contributor

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.

Copy link
Contributor

@stubailo stubailo left a 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.
Copy link
Contributor

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) => {
Copy link
Contributor

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;
Copy link
Contributor

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).
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link

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`.
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

@jbaxleyiii jbaxleyiii left a 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.
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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`.
Copy link
Contributor

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(
Copy link
Contributor

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?

@jbaxleyiii jbaxleyiii mentioned this pull request Jul 24, 2017
@jbaxleyiii
Copy link
Contributor

@evanshauser I've added #11 as well to add some root level npm shortcuts and formatting.

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

Successfully merging this pull request may close these issues.

None yet

5 participants