Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@lightspeed/apollo-next-app
Advanced tools
@lightspeed/apollo-next-app
Apollo Client integration app HOC for Next.js applications that provides prefetching of data on client-side rendering (CSR) and server-side rendering (SSR).
yarn add @lightspeed/apollo-next-app
In your Next.js application, enhance your _app.tsx
component with the withApollo
HOC. We have bundled a simple set of Apollo client instantiation dependencies with this module for convenience:
import React from 'react';
import App, { Container } from 'next/app';
import getConfig from 'next/config';
import { withApollo, ApolloClient, HttpLink, InMemoryCache } from '@lightspeed/apollo-next-app';
// Assumes you have passed `process.env.BASE_GRAPHQL_URL` in your `next.config.js` file:
// ```
// const withLightspeed = require('@lightspeed/config-next');
//
// module.exports = withLightspeed({
// publicRuntimeConfig: {
// baseGraphQLUrl: process.env.BASE_GRAPHQL_URL,
// },
// });
// ```
const { publicRuntimeConfig } = getConfig();
const { baseGraphQLUrl } = publicRuntimeConfig;
class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<Container>
<Component {...pageProps} />
</Container>
);
}
}
export default withApollo({
initApollo: ({ initialState }) =>
new ApolloClient({
link: new HttpLink({
uri: typeof window !== 'undefined' ? '/graphql' : `${baseGraphQLUrl}/graphql`,
credentials: 'include',
}),
cache: new InMemoryCache().restore(initialState || {}),
}),
})(NextApp);
You can now start executing queries by following Apollo Client's guide!
The following configuration options are available to the withApollo
HOC.
Key | Type | Default | Note |
---|---|---|---|
initApollo | function | N/A | Factory function to build the Apollo client |
debug | boolean | false | Enable debug mode |
prefetch | 'always' , 'ssr' or 'never' | 'never' | Prefetch on CSR and SSR, only SSR, or never |
Additionally, you'll have access to the apolloClient
instance in the NextContext
of your page getInitialProps
functions.
MyPage.getInitialProps = (ctx: NextContext) => {
const { apolloClient } = ctx;
// ...and do as you please!
};
FAQs
Apollo Client SSR/CSR integration with Next.js
The npm package @lightspeed/apollo-next-app receives a total of 8 weekly downloads. As such, @lightspeed/apollo-next-app popularity was classified as not popular.
We found that @lightspeed/apollo-next-app demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.