document optimizations v2

This commit is contained in:
Chi Vinh Le
2017-12-07 18:41:46 +01:00
parent f96146bfd9
commit 7072aa013b
6 changed files with 32 additions and 29 deletions
@@ -0,0 +1,23 @@
import graphql from '@coralproject/graphql-anywhere-optimized';
import {createTypeGetter} from 'graphql-ast-tools';
import introspectionData from './introspection.json';
// User typeGetter to get more optimized documents.
const typeGetter = createTypeGetter(introspectionData);
// Use global fragment cache for transformed fragments.
const fragmentMap = {};
export default (...args) => {
while (args.length < 7) {
args.push(undefined);
}
const transformOptions = {
typeGetter,
fragmentMap,
};
args[6] = transformOptions;
return graphql(...args);
};
-4
View File
@@ -124,10 +124,6 @@ export async function createContext({
const plugins = createPluginsService(pluginsConfig);
const graphql = createGraphQLService(
createGraphQLRegistry(plugins.getSlotFragments.bind(plugins)),
{
introspectionData,
optimize: process.env.NODE_ENV === 'production',
},
);
if (!notification) {
+1 -17
View File
@@ -1,4 +1,3 @@
import {transformDocument, createTypeGetter} from 'graphql-ast-tools';
import {addTypenameToDocument} from 'apollo-client/queries/queryTransform';
/**
@@ -6,18 +5,7 @@ import {addTypenameToDocument} from 'apollo-client/queries/queryTransform';
* @param {string} basename base path of the url
* @return {Object} histor service
*/
export function createGraphQLService(registry, {
introspectionData,
optimize = false,
}) {
const transformOptions = {
typeGetter: optimize && introspectionData ? createTypeGetter(introspectionData) : null,
// Use shared fragment map.
// Attention: Fragment names must be unique otherwise weird things will happen.
fragmentMap: {},
};
export function createGraphQLService(registry) {
return {
registry,
resolveDocument(documentOrCallback, props, context) {
@@ -26,10 +14,6 @@ export function createGraphQLService(registry, {
: documentOrCallback;
document = registry.resolveFragments(document);
if (optimize) {
document = transformDocument(document, transformOptions);
}
// We also add typenames to the document which apollo would usually do,
// but we also use the network interface in subscriptions directly
// which require the resolved typenames.