From 4477c0981ff6bbb97654af2fc50539b98c51960f Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 8 Dec 2017 23:38:10 +0100 Subject: [PATCH 1/3] Reapply optimizations --- client/coral-framework/graphql/anywhere.js | 23 ++++++++++++++++++++ client/coral-framework/services/bootstrap.js | 4 ---- client/coral-framework/services/graphql.js | 18 +-------------- package.json | 2 +- webpack.config.js | 2 +- yarn.lock | 12 +++++----- 6 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 client/coral-framework/graphql/anywhere.js diff --git a/client/coral-framework/graphql/anywhere.js b/client/coral-framework/graphql/anywhere.js new file mode 100644 index 000000000..7a93f16ea --- /dev/null +++ b/client/coral-framework/graphql/anywhere.js @@ -0,0 +1,23 @@ +import graphql from '@coralproject/graphql-anywhere-optimized'; +import {createTypeGetter} from 'graphql-ast-tools'; +import introspectionData from './introspection.json'; + +// Use 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); +}; diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 3ef6629c1..1328b169d 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -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) { diff --git a/client/coral-framework/services/graphql.js b/client/coral-framework/services/graphql.js index fb40ecf71..d7b132bd4 100644 --- a/client/coral-framework/services/graphql.js +++ b/client/coral-framework/services/graphql.js @@ -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. diff --git a/package.json b/package.json index 4d556c48b..1273015fe 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "fs-extra": "^4.0.1", "gql-merge": "^0.0.4", "graphql": "^0.9.1", - "graphql-ast-tools": "^0.1.5", + "graphql-ast-tools": "0.2.3", "graphql-docs": "0.2.0", "graphql-errors": "^2.1.0", "graphql-redis-subscriptions": "1.3.0", diff --git a/webpack.config.js b/webpack.config.js index 60a49b6eb..14ac7caf5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -120,7 +120,7 @@ const config = { }, resolve: { alias: { - 'graphql-anywhere': '@coralproject/graphql-anywhere-optimized', + 'graphql-anywhere': path.resolve(__dirname, 'client/coral-framework/graphql/anywhere'), 'plugin-api': path.resolve(__dirname, 'plugin-api/'), plugins: path.resolve(__dirname, 'plugins/'), pluginsConfig: pluginsPath diff --git a/yarn.lock b/yarn.lock index c01e2e85a..ea99f0cfa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,10 +12,10 @@ eslint-plugin-react "^7.3.0" "@coralproject/graphql-anywhere-optimized@^0.1.0": - version "0.1.3" - resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.3.tgz#f92f3906bb04f001aef725697237786752c49bd6" + version "0.1.5" + resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.5.tgz#67c862bf908ea717d9521ea76266b5bc9f109c65" dependencies: - graphql-ast-tools "^0.1.6" + graphql-ast-tools "^0.2.2" "@kadira/storybook-deployer@^1.1.0": version "1.2.0" @@ -3521,9 +3521,9 @@ graphql-anywhere@^3.0.1: version "3.1.0" resolved "https://registry.yarnpkg.com/graphql-anywhere/-/graphql-anywhere-3.1.0.tgz#3ea0d8e8646b5cee68035016a9a7557c15c21e96" -graphql-ast-tools@^0.1.5, graphql-ast-tools@^0.1.6: - version "0.1.6" - resolved "https://registry.yarnpkg.com/graphql-ast-tools/-/graphql-ast-tools-0.1.6.tgz#48eb656434bf4c7dba2a0d4784f1fdb988ab70ed" +graphql-ast-tools@0.2.3, graphql-ast-tools@^0.2.2: + version "0.2.3" + resolved "https://registry.yarnpkg.com/graphql-ast-tools/-/graphql-ast-tools-0.2.3.tgz#447fb05905ebb90f0a5bba81d5715249e9937135" dependencies: apollo-utilities "^1.0.3" From 30073b88f1e6371e607af2577fd15e7fafcfd5cb Mon Sep 17 00:00:00 2001 From: Stephen Donner Date: Wed, 13 Dec 2017 03:49:35 -0600 Subject: [PATCH 2/3] s/setup/setup --- docs/_docs/01-01-talk-quickstart.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_docs/01-01-talk-quickstart.md b/docs/_docs/01-01-talk-quickstart.md index c5e7a20ee..811bfe5ed 100644 --- a/docs/_docs/01-01-talk-quickstart.md +++ b/docs/_docs/01-01-talk-quickstart.md @@ -26,7 +26,7 @@ to persist data. The following versions are supported: An optional dependency for Talk is [Docker](https://www.docker.com/community-edition#/download){:target="_blank"}. -It is used during [development](#development) to setup the database and can be +It is used during [development](#development) to set up the database and can be used to [install via Docker](#installation-from-docker). We have tested Talk and this documentation with versions {{ site.versions.docker }}. @@ -182,4 +182,4 @@ machine. At this point you've successfully installed, configured, and ran your very own instance of Talk! Continue through this documentation on this site to learn more -on how to configure, develop with, and contribute to Talk! \ No newline at end of file +on how to configure, develop with, and contribute to Talk! From df925f5a1a4743a15940ce6469508b09e9b506f6 Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Wed, 13 Dec 2017 07:38:10 -0600 Subject: [PATCH 3/3] Fix logic to generate asset_url even if the asset_id is provided so an error is avoided --- client/coral-embed/src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index f60a88439..935972795 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -70,10 +70,9 @@ export class Talk { // Extract the asset url. if (opts.asset_url) { query.asset_url = opts.asset_url; - } else if (!opts.asset_id) { + } else { - // The asset url was not provided and the asset id was also not provided, - // we need to infer the asset url from details on the page. + // The asset url was not provided so we need to infer the asset url from // details on the page. try { query.asset_url = document.querySelector('link[rel="canonical"]').href;