More integration with the introspection query result

- Auto generate introspection on any change when using  `dev-start`
- Port client to use introspection matcher
This commit is contained in:
Chi Vinh Le
2017-07-25 16:51:41 +07:00
parent 4d6271d255
commit b4244b8671
7 changed files with 10 additions and 91 deletions
+1 -1
View File
@@ -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';
@@ -1,6 +0,0 @@
import {getClient as getFrameworkClient} from 'coral-framework/services/client';
import fragmentMatcher from './fragmentMatcher';
export function getClient() {
return getFrameworkClient({fragmentMatcher});
}
@@ -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;
+1 -1
View File
@@ -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()),
+3 -1
View File
@@ -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
+5 -4
View File
@@ -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": {
@@ -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