-
Notifications
You must be signed in to change notification settings - Fork 266
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
Server Side Rendering window is not defined. #82
Comments
Same problem here using AppSync with a next.js project. |
🤦♂️ how can I just use regular Apollo Client with api key? |
same issue, using the appsync in reactql project.Its working fine(i'm able to get the data using aws-appsync ) but as soon as I import 'aws-appsync' in my project I get the refrence error "window is not defined" looks like 'aws-appsync' is referencing the browser's window object, even if it is only imported, before any usage. |
Not sure is this fix working well.. #110 |
Having the same issue with Nuxt.js |
do you know how to get current href in this frameworks on the server site? |
Hi! We are actively working on removing dependencies on the window object to enable server side rendering without having to polyfill stuff. Stay tuned. If you're curious how this would work in the future (please understand this is experimental and requires for now unpublished modules and unmerged pull requests to third party repos), you can take a look at manueliglesias/urban-pancake (a nextjs web app I am using to test stuff), specifically this piece https://github.com/manueliglesias/urban-pancake/blob/61f167f99793d6573adcf577d975578353d5b70c/lib/initApollo.js#L13-L31 |
@manueliglesias this sounds great :) currently I have implemented https://github.com/zeit/next.js/#custom-app i.e. I have over-ridden _app.js as below:
We could at least get Appsync working with Next.js. However, by above solution we have lost actual SSR capabilities. I must say that Appsync is really great. We have been using it to build a B2B SaaS solution since its preview days :) If Appsync library does remove all dependencies from window and browser objects and also support SSR libraries;,it would be happy days for us :) |
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; } ```
There are only some options left for us:
We don't want to do things that would risk too much. Could you please do something about it?
`ReferenceError: window is not defined
The text was updated successfully, but these errors were encountered: