-
Notifications
You must be signed in to change notification settings - Fork 32
Conversation
A work in progress. Fixes apollographql#6.
- Nicer package.json config ordering. - Cleaner dist directory structure (no redundant src subdirectories). - Added an ES6 module entry to the package for modern bundlers like Rollup and Webpack. - Removed redundant glob argument from the lint script.
I haven't testing it with batching yet, but it should work. |
There is a |
requestOrRequests: GraphQLRequest | GraphQLRequest[], | ||
options: RequestInit, | ||
): RequestInit { | ||
const files = extractFiles(requestOrRequests); |
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 Does it matter that requestOrRequests
is modified by extractFiles
? Or would it be better if extract files did not modify the input:
const { files, modifiedTree } = extractFiles(requestOrRequests)
Keep in mind that there are performance considerations to messing around with objects that contain potentially megabytes of files.
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.
@jaydenseric currently, reqeustOrRequests
isn't used after it is incorporated into the fetch options, so should be safe to modify in constructOptions
/we don't need a defensive copy in apollo-fetch
.
In general from apollo-fetch
's perspective, once we have called an external function, such as constructOptions
, the references passed as arguments should not be used by apollo-fetch
I think the implementation is ready. @evanshauser are you able to explain how to get batching to work here so we can test it out? Help setting up the tests will be much appreciated, I'm not really sure how to go about it. |
@jaydenseric awesome work! The way to get batching enabled is (batch blog): const client = new ApolloClient({
// ... other options ...
shouldBatch: true,
}); This option would mean that all queries would be put into a single batch, so file uploads and regular GraphQL requests would be placed in the same network request. Does your Also, can We're working on a BatchingLink that will perform the batching logic and run a provided function on the batch. |
@evanshauser I'm quite familiar with batching, and import ApolloClient, { createBatchingNetworkInterface } from 'apollo-client'
const client = new ApolloClient({
networkInterface: createBatchingNetworkInterface({
uri: '/graphql'
})
}) But with
|
Yeah - right now all of the logic for batching (collecting multiple requests and sending them as one) lives inside the network interface implementation. I think the correct solution here is to use |
@jaydenseric This looks great! I think we are ready to merge after unit tests for getting the transformation tested for a single request(upload and normal with/without an array) and batched request(two normal, two uploads, and one of each). Not sure about the different errors that can occur from a failed upload, so I'll trust you to include what you feel is relevant. Then after the changelogs are per project, we can announce apollo-fetch-upload! So excited, this will be an awesome addition! We're also planning to add some Continuous deployment into Travis-CI, so if you could add the npm user, mdg, to the apollo-fetch-upload, we can start to hook things up. |
…into apollo-fetch-upload
- Removed config matching defaults. - Individual build target configs instead of inheritance.
@evanshauser So, it's been an unproductive day attempting to create tests. Here are some of the challenges...
I attempted to polyfill For these reasons there are no tests in |
How do supertest and superagent do it? In this case I am starting a import Koa from 'koa'
import body from 'koa-bodyparser'
import { resolve } from 'path'
import request from 'supertest'
import { expect } from 'chai'
import 'mocha'
const app = new Koa()
app.use(body())
createGraphQLServer(app)
const server = app.listen(4004)
describe('GraphQL Server', () => {
it('can upload images', () => {
return request(server)
.post('/graphql')
.field('operationName', 'uploadImages')
.field('query', `mutation uploadImages($location_id: Int!, $images: [File!]!) {
uploadImages(location_id: $location_id, images: $images) {
name slug width height file_name extension mime_type url
owner { id username }
}
}`)
.field('variables', JSON.stringify({
location_id: 3,
}))
.attach('images', resolve(__dirname, 'images', 'image1.jpg'))
.attach('images', resolve(__dirname, 'images', 'image2.jpg'))
.attach('images', resolve(__dirname, 'images', 'image3.jpg'))
.expect(200)
.then(res => {
expect(res.body).to.deep.equal(expected)
})
})
}) Probably I'm missing something ... |
@jaydenseric This is incredible work! Great job! So happy to have |
An
apollo-fetch-upload
package to fix #6, superseding #8.This package allows the use of files anywhere in a GraphQL request (in theory, not just in
variables
) and is compatible withapollo-upload-server
.To try it out:
apollo-fetch/packages/apollo-upload-fetch
runnpm install && npm link
.apollo-fetch-upload
branch.apollo-upload-examples/app
runnpm install && npm link apollo-upload-fetch
. You may have to manually removeapollo-upload-fetch
from the dependencies first since it is not published yet.apollo-upload-examples
.TODO: