# apollo-client-ssr

> The necessary HOC and hook for SSR. e.g. Next.js.

Latest version **0.0.11** (published 2020-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install apollo-client-ssr
pnpm add apollo-client-ssr
yarn add apollo-client-ssr
bun add apollo-client-ssr
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2020-07-14 |
| First published | 2020-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 11 |
| Unpacked size | 38.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | onichandame |
| Maintainers | onichandame |

## Links

- npm: https://www.npmjs.com/package/apollo-client-ssr
- npm.io page: https://npm.io/package/apollo-client-ssr

## Dependencies (11)

- [graphql](https://npm.io/package/graphql.md) ^15.3.0
- [apollo-link](https://npm.io/package/apollo-link.md) ^1.2.14
- [apollo-client](https://npm.io/package/apollo-client.md) ^2.6.10
- [apollo-link-ws](https://npm.io/package/apollo-link-ws.md) ^1.0.20
- [apollo-link-http](https://npm.io/package/apollo-link-http.md) ^1.5.17
- [apollo-utilities](https://npm.io/package/apollo-utilities.md) ^1.3.4
- [next-with-apollo](https://npm.io/package/next-with-apollo.md) ^5.1.0
- [@apollo/react-ssr](https://npm.io/package/@apollo/react-ssr.md) ^3.1.5
- [isomorphic-unfetch](https://npm.io/package/isomorphic-unfetch.md) ^3.0.0
- [@apollo/react-hooks](https://npm.io/package/@apollo/react-hooks.md) ^3.1.5
- [apollo-cache-inmemory](https://npm.io/package/apollo-cache-inmemory.md) ^1.6.6

## Recent versions

- 0.0.11 (latest) — 2020-07-14
- 0.0.10 — 2020-06-03
- 0.0.9 — 2020-06-03
- 0.0.8 — 2020-06-03
- 0.0.7 — 2020-06-03
- 0.0.6 — 2020-06-03
- 0.0.5 — 2020-06-03
- 0.0.4 — 2020-06-03
- 0.0.3 — 2020-06-03
- 0.0.2 — 2020-04-27
- 0.0.1 — 2020-04-27
- 0.0.0 — 2020-04-27

## README

# Apollo Client for SSR

The necessary HOC and hook for SSR. e.g. Next.js.

This is a thin wrapper around [next-with-apollo](https://www.npmjs.com/package/next-with-apollo). If you don't need subscription to work with SSR, please use it instead.

# Author

[onichandame](https://github.com/onichandame)

# Usage

```typescript
import React, { FC } from 'react'
import gql from 'graphql-tag'
import { withApollo } from 'apollo-client-ssr'
import { useQuery, useMutation, useSubscription } from 'apollo-client-ssr'

const QUERY = gql`
  query book($id: String!){
    book(id: $id){
      author
    }
  }
`

const MUTATION = gql`
  mutation book($id: String!, $authoor: String!){
    book(id: $id, author: $authoor)
  }
`

const SUBSCRIPTION = gql`
  subscription book($id: String!){
    book(id: $id){
      author
    }
  }
`

const Query: FC = () => {
  const { data,loading } = useQuery<{book: {author: string}}>(QUERY, { variables: {id: '1'} })
  if(loading || !data) return <p>loading...</p>
  else return <p>{`book 1 is authored by ${data.book.author}`}</p>
}

export const QueryAuthor = withApollo(Query, {
  url: 'localhost/graphql'
})

const Mutation: FC = () => {
  const { data, loading } = useMutation<boolean>(MUTATION, {variables: {id: '1', author: 'shakespeare'}})
  if(loading || !data) return <p>loading...</p>
  else return <p>{data.book ? 'done' : 'failed'}</p>
}

export const MutateAuthor = withApollo(Mutation, {
  url: 'localhost/graphql'
})

const Subscription: FC = () => {
  const { data, loading } = useSubscription<{book: {author: string}}>({
    query: [ QUERY, { variables: {id: '1'} }], // needed for the first render on the server side
    subscription: [ SUBSCRIPTION, { variables: {id: '1'} } ]
  })
  if(loading || !data) return <p>loading...</p>
  else return <p>{`book 1 is authored by ${data.book.author}`}</p>
}

export const SubscriptionAuthor = withApollo(Subscription, {
  url: 'localhost/graphql'
})
```

# License

MIT

# Contributing

Please open issues or PRs to discuss whatever you think that will make this tool more convenient!

# Roadmap

- add SSL support for http and ws

---
_Source: https://npm.io/package/apollo-client-ssr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
