Put document optimizations behind a option

This commit is contained in:
Chi Vinh Le
2017-12-01 16:54:45 +01:00
parent 015e3d3ed9
commit 835d30d362
2 changed files with 20 additions and 8 deletions
+4 -1
View File
@@ -124,7 +124,10 @@ export async function createContext({
const plugins = createPluginsService(pluginsConfig);
const graphql = createGraphQLService(
createGraphQLRegistry(plugins.getSlotFragments.bind(plugins)),
introspectionData,
{
introspectionData,
optimize: true,
},
);
if (!notification) {
+16 -7
View File
@@ -2,16 +2,21 @@ import reduceDocument, {createTypeGetter} from '../graphql/reduceDocument';
import {addTypenameToDocument} from 'apollo-client/queries/queryTransform';
/**
* createHistory returns the history service for react router
* createGraphQLService
* @param {string} basename base path of the url
* @return {Object} histor service
*/
export function createGraphQLService(registry, introspectionData) {
const typeGetter = createTypeGetter(introspectionData);
export function createGraphQLService(registry, {
introspectionData,
optimize = false,
}) {
const reduceOptions = {
typeGetter: optimize && introspectionData ? createTypeGetter(introspectionData) : null,
// Use shared fragment map.
// Attention: Fragment names must be unique otherwise weird things will happen.
const fragmentMap = {};
// Use shared fragment map.
// Attention: Fragment names must be unique otherwise weird things will happen.
fragmentMap: {},
};
return {
registry,
@@ -19,7 +24,11 @@ export function createGraphQLService(registry, introspectionData) {
let document = typeof documentOrCallback === 'function'
? documentOrCallback(props, context)
: documentOrCallback;
document = reduceDocument(registry.resolveFragments(document), {typeGetter, fragmentMap});
document = registry.resolveFragments(document);
if (optimize) {
document = reduceDocument(document, reduceOptions);
}
// We also add typenames to the document which apollo would usually do,
// but we also use the network interface in subscriptions directly