Setup query batching.
This commit is contained in:
parent
7313415e6f
commit
18b6542e56
@ -1,7 +1,7 @@
|
|||||||
import { ApolloClient } from 'react-apollo'
|
|
||||||
import { createApolloFetchUpload } from 'apollo-fetch-upload'
|
|
||||||
import { print } from 'graphql/language/printer'
|
|
||||||
import 'isomorphic-fetch'
|
import 'isomorphic-fetch'
|
||||||
|
import { ApolloClient } from 'react-apollo'
|
||||||
|
import BatchHttpLink from 'apollo-link-batch-http'
|
||||||
|
import { createApolloFetchUpload } from 'apollo-fetch-upload'
|
||||||
|
|
||||||
// Used in the browser to share a single Apollo Client instance between
|
// Used in the browser to share a single Apollo Client instance between
|
||||||
// decorated components.
|
// decorated components.
|
||||||
@ -12,19 +12,16 @@ let apolloClient = null
|
|||||||
* @param {Object} [initialState] - Apollo client Redux store initial state.
|
* @param {Object} [initialState] - Apollo client Redux store initial state.
|
||||||
* @returns {Object} Apollo Client instance.
|
* @returns {Object} Apollo Client instance.
|
||||||
*/
|
*/
|
||||||
function createApolloClient(initialState) {
|
const createApolloClient = initialState =>
|
||||||
const apolloFetchUpload = createApolloFetchUpload({
|
new ApolloClient({
|
||||||
uri: process.env.API_URI
|
|
||||||
})
|
|
||||||
|
|
||||||
return new ApolloClient({
|
|
||||||
initialState,
|
initialState,
|
||||||
ssrMode: !process.browser,
|
ssrMode: !process.browser,
|
||||||
networkInterface: {
|
networkInterface: new BatchHttpLink({
|
||||||
query: req => apolloFetchUpload({ ...req, query: print(req.query) })
|
fetch: createApolloFetchUpload({
|
||||||
}
|
uri: process.env.API_URI
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates the Apollo Client instance.
|
* Gets or creates the Apollo Client instance.
|
||||||
|
|||||||
29
app/package-lock.json
generated
29
app/package-lock.json
generated
@ -132,6 +132,14 @@
|
|||||||
"whatwg-fetch": "2.0.3"
|
"whatwg-fetch": "2.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"apollo-fetch": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/apollo-fetch/-/apollo-fetch-0.6.0.tgz",
|
||||||
|
"integrity": "sha1-qumyjBF680SwkeyLpNGlqgR03F0=",
|
||||||
|
"requires": {
|
||||||
|
"isomorphic-fetch": "2.2.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"apollo-fetch-upload": {
|
"apollo-fetch-upload": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -3627,6 +3635,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"apollo-link-batch": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/apollo-link-batch/-/apollo-link-batch-0.1.0.tgz",
|
||||||
|
"integrity": "sha1-fG7zK4wW720qn1EHkcoidkIoNJ0=",
|
||||||
|
"requires": {
|
||||||
|
"apollo-fetch": "0.6.0",
|
||||||
|
"apollo-link-core": "0.5.0",
|
||||||
|
"graphql": "0.10.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"apollo-link-batch-http": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/apollo-link-batch-http/-/apollo-link-batch-http-0.1.0.tgz",
|
||||||
|
"integrity": "sha1-c8M0V2R/AjDtR9zPMzJ98bun/DY=",
|
||||||
|
"requires": {
|
||||||
|
"apollo-fetch": "0.6.0",
|
||||||
|
"apollo-link-batch": "0.1.0",
|
||||||
|
"apollo-link-core": "0.5.0",
|
||||||
|
"graphql": "0.10.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"apollo-link-core": {
|
"apollo-link-core": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/apollo-link-core/-/apollo-link-core-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/apollo-link-core/-/apollo-link-core-0.5.0.tgz",
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"apollo-fetch-upload": "^1.0.0",
|
"apollo-fetch-upload": "^1.0.0",
|
||||||
|
"apollo-link-batch-http": "^0.1.0",
|
||||||
"babel-plugin-transform-inline-environment-variables": "^0.1.1",
|
"babel-plugin-transform-inline-environment-variables": "^0.1.1",
|
||||||
"graphql": "^0.10.5",
|
|
||||||
"next": "^3.0.3",
|
"next": "^3.0.3",
|
||||||
"react": "^15.6.1",
|
"react": "^15.6.1",
|
||||||
"react-apollo": "^1.4.11",
|
"react-apollo": "^1.4.11",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user