Skip to content

Commit dde20fc

Browse files
Skaronatortimneutkens
authored andcommitted
Added note for AWSAppSyncClient (#4611)
I had some trouble to get server side rendering with the AWSAppSyncClient working. I finally found a solution in awslabs/aws-mobile-appsync-sdk-js#82 but it might be worth to share it here as well. Instead of adding a big code block to each file I'll just refer to this Pull Request. ______ In case you want to use the `AWSAppSyncClient` you just need to replace the `create()` function with this function: ```jsx import AWSAppSyncClient from 'aws-appsync'; import { AUTH_TYPE } from 'aws-appsync/lib/link/auth-link'; function create(initialState) { const client = new AWSAppSyncClient({ url: AWS_AppSync.graphqlEndpoint, region: AWS_AppSync.region, auth: { type: AUTH_TYPE.API_KEY, apiKey: AWS_AppSync.apiKey, // Amazon Cognito Federated Identities using AWS Amplify //credentials: () => Auth.currentCredentials(), // Amazon Cognito user pools using AWS Amplify // type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, // jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(), }, disableOffline: true, }, { cache: new InMemoryCache().restore(initialState || {}), ssrMode: true }); return client; } ```
1 parent 9d52268 commit dde20fc

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

examples/with-apollo-and-redux-saga/lib/initApollo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (!process.browser) {
1111
}
1212

1313
function create(initialState) {
14+
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
1415
return new ApolloClient({
1516
connectToDevTools: process.browser,
1617
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)

examples/with-apollo-and-redux/lib/initApollo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (!process.browser) {
1111
}
1212

1313
function create(initialState) {
14+
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
1415
return new ApolloClient({
1516
connectToDevTools: process.browser,
1617
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
@@ -35,4 +36,4 @@ export default function initApollo(initialState) {
3536
}
3637

3738
return apolloClient
38-
}
39+
}

examples/with-apollo-auth/lib/initApollo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function create (initialState, { getToken }) {
2626
}
2727
})
2828

29+
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
2930
return new ApolloClient({
3031
connectToDevTools: process.browser,
3132
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)

examples/with-apollo/lib/init-apollo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (!process.browser) {
1111
}
1212

1313
function create(initialState) {
14+
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
1415
return new ApolloClient({
1516
connectToDevTools: process.browser,
1617
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)

0 commit comments

Comments
 (0)