mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 17:45:56 +08:00
Put document optimizations behind a option
This commit is contained in:
+4
-1
@@ -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) {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user