Skip to content

Commit 61655b1

Browse files
author
Guillaume Chau
committed
feat(ui): Project creation working!
1 parent 49d2b4d commit 61655b1

33 files changed

+702
-431
lines changed

packages/@vue/cli-shared-utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
'spinner',
55
'validate',
66
'openBrowser',
7-
'pluginResolution'
7+
'pluginResolution',
8+
'exit'
89
].forEach(m => {
910
Object.assign(exports, require(`./lib/${m}`))
1011
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports.exitProcess = true
2+
3+
exports.exit = function (code) {
4+
if (exports.exitProcess) {
5+
process.exit(code)
6+
} else if (code > 0) {
7+
throw new Error(`Process exited with code ${code}`)
8+
}
9+
}

packages/@vue/cli-shared-utils/lib/validate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const joi = require('joi')
2+
const { exit } = require('./exit')
23

34
// proxy to joi for option validation
45
exports.createSchema = fn => fn(joi)
@@ -10,7 +11,7 @@ exports.validate = (obj, schema, cb) => {
1011
if (process.env.VUE_CLI_TEST) {
1112
throw err
1213
} else {
13-
process.exit(1)
14+
exit(1)
1415
}
1516
}
1617
})

packages/@vue/cli-ui/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @vue/cli-ui
2+
3+
Start development version:
4+
5+
```
6+
yarn run serve
7+
```
8+
9+
In another terminal:
10+
11+
```
12+
yarn run graphql-api
13+
```

packages/@vue/cli-ui/package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@
88
"graphql-api": "vue-cli-service graphql-api",
99
"run-graphql-api": "vue-cli-service run-graphql-api"
1010
},
11+
"dependencies": {
12+
"graphql": "^0.13.0",
13+
"lowdb": "^1.0.0",
14+
"mkdirp": "^0.5.1",
15+
"rimraf": "^2.6.2",
16+
"shortid": "^2.2.8"
17+
},
1118
"devDependencies": {
1219
"@vue/cli-plugin-babel": "^3.0.0-beta.3",
1320
"@vue/cli-plugin-eslint": "^3.0.0-beta.3",
1421
"@vue/cli-service": "^3.0.0-beta.3",
1522
"@vue/eslint-config-standard": "^3.0.0-beta.3",
16-
"@vue/ui": "^0.1.6",
17-
"apollo-cache-inmemory": "^1.0.0",
18-
"apollo-client": "^2.0.1",
19-
"apollo-link": "^1.0.0",
20-
"apollo-link-context": "^1.0.5",
21-
"apollo-link-http": "^1.0.0",
22-
"apollo-link-persisted-queries": "^0.1.0",
23+
"@vue/ui": "^0.1.9",
24+
"apollo-cache-inmemory": "^1.1.10",
25+
"apollo-client": "^2.2.6",
26+
"apollo-link": "^1.2.1",
27+
"apollo-link-http": "^1.5.3",
2328
"apollo-link-state": "^0.4.0",
2429
"apollo-link-ws": "^1.0.0",
25-
"apollo-upload-client": "^7.0.0-alpha.4",
26-
"apollo-utilities": "^1.0.1",
27-
"graphql": "^0.13.0",
30+
"apollo-utilities": "^1.0.9",
31+
"eslint": "^4.16.0",
2832
"graphql-tag": "^2.5.0",
2933
"lint-staged": "^6.0.0",
30-
"lowdb": "^1.0.0",
31-
"mkdirp": "^0.5.1",
32-
"shortid": "^2.2.8",
3334
"stylus": "^0.54.5",
3435
"stylus-loader": "^3.0.1",
3536
"subscriptions-transport-ws": "^0.9.5",
@@ -62,8 +63,5 @@
6263
"vue-cli-service lint",
6364
"git add"
6465
]
65-
},
66-
"dependencies": {
67-
"eslint": "^4.16.0"
6866
}
6967
}

packages/@vue/cli-ui/src/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<router-view/>
55
</div>
66

7-
<StatusBar/>
7+
<StatusBar
8+
@project="$router.push({ name: 'project-select' })"
9+
/>
810
</div>
911
</template>
1012

packages/@vue/cli-ui/src/apollo.js

Lines changed: 20 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,16 @@
11
import { ApolloClient } from 'apollo-client'
22
import { split, ApolloLink } from 'apollo-link'
33
import { HttpLink } from 'apollo-link-http'
4-
import { createUploadLink } from 'apollo-upload-client'
54
import { InMemoryCache } from 'apollo-cache-inmemory'
6-
import { SubscriptionClient, MessageTypes } from 'subscriptions-transport-ws'
5+
import { SubscriptionClient } from 'subscriptions-transport-ws'
76
import { WebSocketLink } from 'apollo-link-ws'
87
import { getMainDefinition } from 'apollo-utilities'
9-
import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
10-
import { setContext } from 'apollo-link-context'
118
import { withClientState } from 'apollo-link-state'
129
import defaults from './state/defaults'
1310
import resolvers from './state/resolvers'
1411

15-
function getAuth () {
16-
// get the authentication token from local storage if it exists
17-
const token = localStorage.getItem('apollo-token')
18-
// return the headers to the context so httpLink can read them
19-
return token ? `Bearer ${token}` : ''
20-
}
21-
22-
function restartWebsockets (wsClient) {
23-
// Copy current operations
24-
const operations = Object.assign({}, wsClient.operations)
25-
26-
// Close connection
27-
wsClient.close(true)
28-
29-
// Open a new one
30-
wsClient.connect()
31-
32-
// Push all current operations to the new connection
33-
Object.keys(operations).forEach(id => {
34-
wsClient.sendMessage(
35-
id,
36-
MessageTypes.GQL_START,
37-
operations[id].options
38-
)
39-
})
40-
}
41-
4212
// Create the apollo client
43-
export default function createApolloClient ({ ssr, base, endpoints, persisting }) {
13+
export default function createApolloClient ({ base, endpoints, persisting }) {
4414
let link
4515
let wsClient
4616

@@ -49,102 +19,36 @@ export default function createApolloClient ({ ssr, base, endpoints, persisting }
4919
uri: base + endpoints.graphql
5020
})
5121

52-
// HTTP Auth header injection
53-
const authLink = setContext((_, { headers }) => ({
54-
headers: {
55-
...headers,
56-
authorization: getAuth()
57-
}
58-
}))
59-
60-
// Concat all the http link parts
61-
httpLink = authLink.concat(httpLink)
62-
if (persisting) {
63-
httpLink = createPersistedQueryLink().concat(httpLink)
64-
}
65-
6622
// Apollo cache
6723
const cache = new InMemoryCache()
6824

6925
// Client-side state
7026
const stateLink = withClientState({ defaults, cache, resolvers })
7127

72-
if (!ssr) {
73-
// If on the client, recover the injected state
74-
if (typeof window !== 'undefined') {
75-
// eslint-disable-next-line no-underscore-dangle
76-
const state = window.__APOLLO_STATE__
77-
if (state) {
78-
// If you have multiple clients, use `state.<client_id>`
79-
cache.restore(state.defaultClient)
80-
}
81-
}
82-
83-
// Web socket
84-
wsClient = new SubscriptionClient(base.replace(/^https?/i, 'ws' + (process.env.NODE_ENV === 'production' ? 's' : '')) +
85-
endpoints.subscription, {
86-
reconnect: true,
87-
connectionParams: () => ({
88-
'Authorization': getAuth()
89-
})
90-
})
91-
92-
// Create the subscription websocket link
93-
const wsLink = new WebSocketLink(wsClient)
94-
95-
// File upload
96-
const uploadLink = authLink.concat(createUploadLink({
97-
uri: base + endpoints.graphql
98-
}))
28+
// Web socket
29+
wsClient = new SubscriptionClient(base.replace(/^https?/i, 'ws' + (process.env.NODE_ENV === 'production' ? 's' : '')) +
30+
endpoints.subscription, {
31+
reconnect: true
32+
})
9933

100-
// using the ability to split links, you can send data to each link
101-
// depending on what kind of operation is being sent
102-
httpLink = split(
103-
operation => operation.getContext().upload,
104-
uploadLink,
105-
httpLink
106-
)
34+
// Create the subscription websocket link
35+
const wsLink = new WebSocketLink(wsClient)
10736

108-
link = split(
109-
// split based on operation type
110-
({ query }) => {
111-
const { kind, operation } = getMainDefinition(query)
112-
return kind === 'OperationDefinition' &&
113-
operation === 'subscription'
114-
},
115-
wsLink,
116-
httpLink
117-
)
118-
} else {
119-
// On the server, we don't want WebSockets
120-
link = httpLink
121-
}
37+
link = split(
38+
// split based on operation type
39+
({ query }) => {
40+
const { kind, operation } = getMainDefinition(query)
41+
return kind === 'OperationDefinition' &&
42+
operation === 'subscription'
43+
},
44+
wsLink,
45+
httpLink
46+
)
12247

12348
const apolloClient = new ApolloClient({
12449
link: ApolloLink.from([stateLink, link]),
125-
cache,
126-
// Additional options
127-
...(ssr ? {
128-
// Set this on the server to optimize queries when SSR
129-
ssrMode: true
130-
} : {
131-
// This will temporary disable query force-fetching
132-
ssrForceFetchDelay: 100,
133-
// Apollo devtools
134-
connectToDevTools: process.env.NODE_ENV !== 'production'
135-
})
50+
cache
13651
})
13752

138-
apolloClient.$onLogin = token => {
139-
localStorage.setItem('apollo-token', token)
140-
if (wsClient) restartWebsockets(wsClient)
141-
}
142-
143-
apolloClient.$onLogout = () => {
144-
localStorage.removeItem('apollo-token')
145-
if (wsClient) restartWebsockets(wsClient)
146-
apolloClient.resetStore()
147-
}
148-
14953
return apolloClient
15054
}

0 commit comments

Comments
 (0)