diff --git a/client/coral-embed-stream/src/actions/auth.js b/client/coral-embed-stream/src/actions/auth.js index 4599a1cc7..22d46a768 100644 --- a/client/coral-embed-stream/src/actions/auth.js +++ b/client/coral-embed-stream/src/actions/auth.js @@ -304,8 +304,6 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -const ErrNotLoggedIn = new Error('Not logged in'); - export const checkLogin = () => (dispatch, _, {rest, client, pym, storage}) => { dispatch(checkLoginRequest()); rest('/auth') @@ -314,7 +312,7 @@ export const checkLogin = () => (dispatch, _, {rest, client, pym, storage}) => { if (storage) { storage.removeItem('token'); } - throw ErrNotLoggedIn; + throw new Error('Not logged in'); } // Reset the websocket. @@ -329,9 +327,7 @@ export const checkLogin = () => (dispatch, _, {rest, client, pym, storage}) => { } }) .catch((error) => { - if (error !== ErrNotLoggedIn) { - console.error(error); - } + console.error(error); if (error.status && error.status === 401 && storage) { // Unauthorized. diff --git a/client/coral-embed-stream/src/graphql/utils.js b/client/coral-embed-stream/src/graphql/utils.js index 8ab24d91f..0c46b45e3 100644 --- a/client/coral-embed-stream/src/graphql/utils.js +++ b/client/coral-embed-stream/src/graphql/utils.js @@ -141,18 +141,18 @@ export function findCommentWithId(nodes, id) { return findComment(nodes, (node) => node.id === id); } -export function findCommentInEmbedQuery(props, callbackOrId) { +export function findCommentInEmbedQuery(root, callbackOrId) { let callback = callbackOrId; if (typeof callbackOrId === 'string') { callback = (node) => node.id === callbackOrId; } - if (props.asset.comment) { - return findComment([getTopLevelParent(props.asset.comment)], callback); + if (root.asset.comment) { + return findComment([getTopLevelParent(root.asset.comment)], callback); } - if (!props.asset.comments) { + if (!root.asset.comments) { return false; } - return findComment(props.asset.comments.nodes, callback); + return findComment(root.asset.comments.nodes, callback); } function findAndInsertFetchedComments(parent, comments, parent_id) { diff --git a/client/coral-embed-stream/src/tabs/stream/containers/Stream.js b/client/coral-embed-stream/src/tabs/stream/containers/Stream.js index b4f375632..dad69b960 100644 --- a/client/coral-embed-stream/src/tabs/stream/containers/Stream.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/Stream.js @@ -108,7 +108,7 @@ class StreamContainer extends React.Component { } loadNewReplies = (parent_id) => { - const comment = findCommentInEmbedQuery(this.props, parent_id); + const comment = findCommentInEmbedQuery(this.props.root, parent_id); return this.props.data.fetchMore({ query: LOAD_MORE_QUERY, diff --git a/client/coral-framework/graphql/anywhere.js b/client/coral-framework/graphql/anywhere.js deleted file mode 100644 index 7a93f16ea..000000000 --- a/client/coral-framework/graphql/anywhere.js +++ /dev/null @@ -1,23 +0,0 @@ -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 1328b169d..3ef6629c1 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -124,6 +124,10 @@ 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 d7b132bd4..fb40ecf71 100644 --- a/client/coral-framework/services/graphql.js +++ b/client/coral-framework/services/graphql.js @@ -1,3 +1,4 @@ +import {transformDocument, createTypeGetter} from 'graphql-ast-tools'; import {addTypenameToDocument} from 'apollo-client/queries/queryTransform'; /** @@ -5,7 +6,18 @@ import {addTypenameToDocument} from 'apollo-client/queries/queryTransform'; * @param {string} basename base path of the url * @return {Object} histor service */ -export function createGraphQLService(registry) { +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: {}, + }; + return { registry, resolveDocument(documentOrCallback, props, context) { @@ -14,6 +26,10 @@ 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 1273015fe..4712a75c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "talk", - "version": "3.8.2", + "version": "3.8.1", "description": "A better commenting experience from Mozilla, The New York Times, and the Washington Post. https://coralproject.net", "main": "app.js", "private": true, @@ -106,7 +106,7 @@ "fs-extra": "^4.0.1", "gql-merge": "^0.0.4", "graphql": "^0.9.1", - "graphql-ast-tools": "0.2.3", + "graphql-ast-tools": "^0.1.5", "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 14ac7caf5..60a49b6eb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -120,7 +120,7 @@ const config = { }, resolve: { alias: { - 'graphql-anywhere': path.resolve(__dirname, 'client/coral-framework/graphql/anywhere'), + 'graphql-anywhere': '@coralproject/graphql-anywhere-optimized', 'plugin-api': path.resolve(__dirname, 'plugin-api/'), plugins: path.resolve(__dirname, 'plugins/'), pluginsConfig: pluginsPath diff --git a/yarn.lock b/yarn.lock index ea99f0cfa..c01e2e85a 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.5" - resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.5.tgz#67c862bf908ea717d9521ea76266b5bc9f109c65" + version "0.1.3" + resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.3.tgz#f92f3906bb04f001aef725697237786752c49bd6" dependencies: - graphql-ast-tools "^0.2.2" + graphql-ast-tools "^0.1.6" "@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.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" +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" dependencies: apollo-utilities "^1.0.3"