Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added note for AWSAppSyncClient #4611

Merged
merged 2 commits into from
Jun 29, 2018
Merged

Conversation

Skaronator
Copy link
Contributor

@Skaronator Skaronator commented Jun 15, 2018

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:

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;
}

@timneutkens timneutkens merged commit dde20fc into vercel:canary Jun 29, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants