Skip to content

Commit

Permalink
Life improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lfades committed Jan 7, 2020
1 parent e578812 commit 83f131e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type WithApolloPageContext = {
apolloClient: TApolloClient
} & NextPageContext

let apolloClient: TApolloClient
let globalApolloClient: TApolloClient

/**
* Creates and provides the apolloContext
Expand Down Expand Up @@ -126,11 +126,11 @@ function initApolloClient(initialState?: any) {
}

// Reuse client on the client-side
if (!apolloClient) {
apolloClient = createApolloClient(initialState)
if (!globalApolloClient) {
globalApolloClient = createApolloClient(initialState)
}

return apolloClient
return globalApolloClient
}

/**
Expand Down
32 changes: 14 additions & 18 deletions examples/with-typescript-graphql/next.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
module.exports = withTypeScriptGraphQL()
module.exports = {
webpack(config, options) {
config.module.rules.push({
test: /\.graphql$/,
exclude: /node_modules/,
use: [options.defaultLoaders.babel, { loader: 'graphql-let/loader' }],
})

function withTypeScriptGraphQL(nextConfig = {}) {
return Object.assign({}, nextConfig, {
webpack(config, options) {
config.module.rules.push({
test: /\.graphql$/,
exclude: /node_modules/,
use: [options.defaultLoaders.babel, { loader: 'graphql-let/loader' }],
})
config.module.rules.push({
test: /\.graphqls$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
})

config.module.rules.push({
test: /\.graphqls$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
})

return config
},
})
return config
},
}
12 changes: 6 additions & 6 deletions examples/with-typescript-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"version": "0.1.0",
"author": "",
"license": "ISC",
"scripts": {
"codegen": "graphql-let",
"dev": "yarn codegen && next",
"build": "yarn codegen && next build",
"start": "next start"
},
"dependencies": {
"@apollo/react-common": "3.1.3",
"@apollo/react-components": "^3.1.3",
Expand All @@ -27,11 +33,5 @@
"@types/react": "^16.9.17",
"graphql-let": "^0.3.2",
"typescript": "^3.7.4"
},
"scripts": {
"codegen": "graphql-let",
"dev": "yarn codegen && next",
"build": "yarn codegen && next build",
"start": "next start"
}
}
6 changes: 3 additions & 3 deletions examples/with-typescript-graphql/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import withApolo from '../lib/with-apolo'
import withApollo from '../lib/with-apollo'
import Link from 'next/link'
import { useViewerQuery } from './viewer.graphql'
import { useViewerQuery } from '../lib/viewer.graphql'

const Index = () => {
const { data } = useViewerQuery()
Expand All @@ -21,4 +21,4 @@ const Index = () => {
return <div>...</div>
}

export default withApolo(Index)
export default withApollo(Index)

0 comments on commit 83f131e

Please sign in to comment.