diff --git a/client/coral-admin/src/index.js b/client/coral-admin/src/index.js index 29df3753c..382f5101d 100644 --- a/client/coral-admin/src/index.js +++ b/client/coral-admin/src/index.js @@ -3,7 +3,7 @@ import {render} from 'react-dom'; import {ApolloProvider} from 'react-apollo'; import smoothscroll from 'smoothscroll-polyfill'; -import {getClient} from './services/client'; +import {getClient} from 'coral-framework/services/client'; import store from './services/store'; import App from './components/App'; diff --git a/client/coral-admin/src/services/client.js b/client/coral-admin/src/services/client.js deleted file mode 100644 index 934de2c9e..000000000 --- a/client/coral-admin/src/services/client.js +++ /dev/null @@ -1,6 +0,0 @@ -import {getClient as getFrameworkClient} from 'coral-framework/services/client'; -import fragmentMatcher from './fragmentMatcher'; - -export function getClient() { - return getFrameworkClient({fragmentMatcher}); -} diff --git a/client/coral-admin/src/services/fragmentMatcher.js b/client/coral-admin/src/services/fragmentMatcher.js deleted file mode 100644 index 231c0fa2b..000000000 --- a/client/coral-admin/src/services/fragmentMatcher.js +++ /dev/null @@ -1,65 +0,0 @@ -import {IntrospectionFragmentMatcher} from 'apollo-client'; - -// TODO this is a short-term fix -// we need to set up something to query the server for the schema before ApolloClient initialization -// https://github.com/apollographql/apollo-client/issues/1555#issuecomment-295834774 -const fm = new IntrospectionFragmentMatcher({ - introspectionQueryResultData: { - __schema: { - types: [ - { - kind: 'INTERFACE', - name: 'UserError', - possibleTypes: [ - {name: 'GenericUserError'}, - {name: 'ValidationUserError'} - ] - }, - { - kind: 'INTERFACE', - name: 'Response', - possibleTypes: [ - {name: 'CreateCommentResponse'}, - {name: 'CreateFlagResponse'}, - {name: 'CreateDontAgreeResponse'}, - {name: 'DeleteActionResponse'}, - {name: 'SetUserStatusResponse'}, - {name: 'SuspendUserResponse'}, - {name: 'SetCommentStatusResponse'}, - {name: 'ModifyTagResponse'}, - {name: 'IgnoreUserResponse'}, - {name: 'StopIgnoringUserResponse'} - ] - }, - { - kind: 'INTERFACE', - name: 'Action', - possibleTypes: [ - {name: 'DefaultAction'}, - {name: 'FlagAction'}, - {name: 'DontAgreeAction'} - ] - }, - { - kind: 'INTERFACE', - name: 'ActionSummary', - possibleTypes: [ - {name: 'DefaultActionSummary'}, - {name: 'FlagActionSummary'}, - {name: 'DontAgreeActionSummary'} - ] - }, - { - kind: 'INTERFACE', - name: 'AssetActionSummary', - possibleTypes: [ - {name: 'DefaultAssetActionSummary'}, - {name: 'FlagAssetActionSummary'} - ] - } - ] - } - } -}); - -export default fm; diff --git a/client/coral-admin/src/services/store.js b/client/coral-admin/src/services/store.js index 06cb3c758..ca29c15c8 100644 --- a/client/coral-admin/src/services/store.js +++ b/client/coral-admin/src/services/store.js @@ -1,7 +1,7 @@ import {createStore, combineReducers, applyMiddleware, compose} from 'redux'; import thunk from 'redux-thunk'; import mainReducer from '../reducers'; -import {getClient} from './client'; +import {getClient} from 'coral-framework/services/client'; const middlewares = [ applyMiddleware(getClient().middleware()), diff --git a/client/coral-framework/services/client.js b/client/coral-framework/services/client.js index 307646db0..b266822fb 100644 --- a/client/coral-framework/services/client.js +++ b/client/coral-framework/services/client.js @@ -1,8 +1,9 @@ -import ApolloClient, {addTypename} from 'apollo-client'; +import ApolloClient, {addTypename, IntrospectionFragmentMatcher} from 'apollo-client'; import {networkInterface} from './transport'; import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws'; import MessageTypes from 'subscriptions-transport-ws/dist/message-types'; import {getAuthToken} from '../helpers/request'; +import introspectionQueryResultData from '../graphql/introspection.json'; let client, wsClient = null, wsClientToken = null; @@ -59,6 +60,7 @@ export function getClient(options = {}) { ...options, connectToDevTools: true, addTypename: true, + fragmentMatcher: new IntrospectionFragmentMatcher({introspectionQueryResultData}), queryTransformer: addTypename, dataIdFromObject: (result) => { if (result.id && result.__typename) { // eslint-disable-line no-underscore-dangle diff --git a/package.json b/package.json index 5e147a781..2c7ee6a69 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "scripts": { "postinstall": "./bin/cli plugins reconcile --skip-remote", "start": "./bin/cli serve -j -w", - "dev-start": "nodemon -w . -w bin/cli -w bin/cli-serve --config .nodemon.json --exec \"./bin/cli -c .env serve -j -w\"", - "prebuild": "WEBPACK=true NODE_ENV=test ./scripts/generateIntrospectionResult.js", + "dev-start": "nodemon -w . -w bin/cli -w bin/cli-serve --config .nodemon.json --exec \"yarn generate-introspection && ./bin/cli -c .env serve -j -w\"", + "prebuild": "yarn generate-introspection", "build": "WEBPACK=true NODE_ENV=production webpack -p --config webpack.config.js --bail", - "prebuild-watch": "WEBPACK=true NODE_ENV=test ./scripts/generateIntrospectionResult.js", + "prebuild-watch": "yarn generate-introspection", "build-watch": "WEBPACK=true NODE_ENV=development webpack --progress --config webpack.config.js --watch", "lint": "eslint bin/* .", "lint-fix": "eslint bin/* . --fix", @@ -19,7 +19,8 @@ "e2e": "NODE_ENV=test nightwatch", "poste2e": "NODE_ENV=test scripts/poste2e.sh", "embed-start": "NODE_ENV=development yarn build && ./bin/cli serve --jobs", - "heroku-postbuild": "./bin/cli plugins reconcile && yarn build" + "heroku-postbuild": "./bin/cli plugins reconcile && yarn build", + "generate-introspection": "WEBPACK=true NODE_ENV=test ./scripts/generateIntrospectionResult.js" }, "talk": { "migration": { diff --git a/plugins/talk-plugin-featured-comments/client/containers/Comment.js b/plugins/talk-plugin-featured-comments/client/containers/Comment.js index 2b3de19b5..7080627e6 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/Comment.js +++ b/plugins/talk-plugin-featured-comments/client/containers/Comment.js @@ -32,19 +32,6 @@ export default withFragments({ } } - ## - # TODO: Remove this when we have the IntrospectionFragmentMatcher. - # Currently without this loading more featured comments - # brings apollo into an inconsistent state. - action_summaries { - __typename - count - current_user { - id - } - } - ## - user { id username