diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 4fcc83a52..5e6173355 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -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) { diff --git a/client/coral-framework/services/graphql.js b/client/coral-framework/services/graphql.js index 87b8e220a..859d57d8a 100644 --- a/client/coral-framework/services/graphql.js +++ b/client/coral-framework/services/graphql.js @@ -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