Skip to content

Commit f7a0ba5

Browse files
committed
add @quasar/apollo@next extension
1 parent 3b7b78e commit f7a0ba5

File tree

6 files changed

+290
-2
lines changed

6 files changed

+290
-2
lines changed

apollo.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-env node */
2+
// See https://www.apollographql.com/docs/devtools/apollo-config/
3+
module.exports = {
4+
client: {
5+
service: {
6+
name: 'my-service',
7+
url: 'http://localhost:3000/graphql',
8+
},
9+
// Files processed by the extension
10+
includes: ['src/**/*.vue', 'src/**/*.js', 'src/**/*.ts'],
11+
},
12+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"devDependencies": {
2020
"@babel/eslint-parser": "^7.13.14",
2121
"@quasar/app": "^3.0.0",
22+
"@quasar/quasar-app-extension-apollo": "^2.0.0-beta.3",
2223
"@types/node": "^12.20.21",
2324
"@typescript-eslint/eslint-plugin": "^4.16.1",
2425
"@typescript-eslint/parser": "^4.16.1",

quasar.extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@quasar/apollo": {
3+
"typescript": true
4+
}
5+
}

src/apollo/index.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import type { ApolloClientOptions } from '@apollo/client/core'
2+
import { createHttpLink, InMemoryCache } from '@apollo/client/core'
3+
import type { BootFileParams } from '@quasar/app'
4+
5+
export /* async */ function getClientOptions(
6+
/* {app, router, ...} */ options?: Partial<BootFileParams<any>>
7+
) {
8+
return <ApolloClientOptions<unknown>>Object.assign(
9+
// General options.
10+
<ApolloClientOptions<unknown>>{
11+
link: createHttpLink({
12+
uri:
13+
process.env.GRAPHQL_URI ||
14+
// Change to your graphql endpoint.
15+
'https://example.com/graphql',
16+
}),
17+
18+
cache: new InMemoryCache(),
19+
},
20+
21+
// Specific Quasar mode options.
22+
process.env.MODE === 'spa'
23+
? {
24+
//
25+
}
26+
: {},
27+
process.env.MODE === 'ssr'
28+
? {
29+
//
30+
}
31+
: {},
32+
process.env.MODE === 'pwa'
33+
? {
34+
//
35+
}
36+
: {},
37+
process.env.MODE === 'bex'
38+
? {
39+
//
40+
}
41+
: {},
42+
process.env.MODE === 'cordova'
43+
? {
44+
//
45+
}
46+
: {},
47+
process.env.MODE === 'capacitor'
48+
? {
49+
//
50+
}
51+
: {},
52+
process.env.MODE === 'electron'
53+
? {
54+
//
55+
}
56+
: {},
57+
58+
// dev/prod options.
59+
process.env.DEV
60+
? {
61+
//
62+
}
63+
: {},
64+
process.env.PROD
65+
? {
66+
//
67+
}
68+
: {},
69+
70+
// For ssr mode, when on server.
71+
process.env.MODE === 'ssr' && process.env.SERVER
72+
? {
73+
ssrMode: true,
74+
}
75+
: {},
76+
// For ssr mode, when on client.
77+
process.env.MODE === 'ssr' && process.env.CLIENT
78+
? {
79+
ssrForceFetchDelay: 100,
80+
}
81+
: {}
82+
)
83+
}

src/boot/apollo.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ApolloClient /*, createHttpLink */ } from '@apollo/client/core'
2+
import { ApolloClients } from '@vue/apollo-composable'
3+
import { boot } from 'quasar/wrappers'
4+
import { getClientOptions } from 'src/apollo'
5+
6+
export default boot(
7+
/* async */ ({ app }) => {
8+
// Default client.
9+
const options = /* await */ getClientOptions(/* {app, router ...} */)
10+
const apolloClient = new ApolloClient(options)
11+
12+
// // Additional client `clientA`
13+
// const optionsA = { ...options }
14+
// // Modify options as needed.
15+
// optionsA.link = createHttpLink({ uri: 'http://clientA.example.com' })
16+
// const clientA = new ApolloClient(optionsA)
17+
18+
// // Additional client `clientB`
19+
// const optionsB = { ...options }
20+
// // Modify options as needed.
21+
// optionsB.link = createHttpLink({ uri: 'http://clientB.example.com' })
22+
// const clientB = new ApolloClient(optionsB)
23+
24+
const apolloClients: Record<string, ApolloClient<unknown>> = {
25+
default: apolloClient,
26+
// clientA,
27+
// clientB,
28+
}
29+
30+
app.provide(ApolloClients, apolloClients)
31+
}
32+
)

0 commit comments

Comments
 (0)