apollographql / apollographql/apollo-client-devtools

Dev tools cannot connect to my project with Apollo client and Next.js

Open
#1,687 9 comments 2 reactions 0 assignees View on GitHub
🐞 bug
Dominant language
TypeScript
Stars
1.5k
Forks
172
Avg merge
10m
Merged PRs (30d)
8

Description

When refreshing the Next.js page, Apollo client dev tools cannot connect to my Apollo client. I have `connectToDevTools` enabled in the client.

### Link to Reproduction

```ts
import { ApolloClient, InMemoryCache } from '@apollo/client'

export const client = new ApolloClient({
uri: 'https://graphqlplaceholder.vercel.app/graphql',
cache: new InMemoryCache(),
connectToDevTools: true,

name: 'apollo-client-dev',
version: '1.3',
queryDeduplication: false,
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
},
},
})
```

```tsx
'use client'

import { Button } from '@/components/ui/button'
import { gql, useMutation, useQuery } from '@apollo/client'

const CREATE_POST = gql`
mutation CreatePost {
createPost(post: { userId: 1, title: "title", body: "body" }) {
id
title
body
}
}
`

const GET_POSTS = gql`
query GetPosts {
posts {
id
title
body
}
}
`

type Post = {
id: number
title: string
}

const Home = () => {
const { loading, error, data } = useQuery(GET_POSTS)
const [addPost, { data: mutationData }] = useMutation(CREATE_POST, {
update(cache, { data: { addPost } }) {
cache.modify({
fields: {
posts(existingPosts = []) {
const newPostRef = cache.writeFragment({
data: addPost,
fragment: gql`
fragment NewPost on Post {
id
text
completed
}
`,
})
return [...existingPosts, newPostRef]
},
},
})
},
})

if (loading) return 'Loading...'
if (error) return `Error! ${error.message}`

return (


{
addPost()
console.log(mutationData)
}}
>
addPost

{data.posts.map((post: Post) => (


{post.id}: {post.title}


))}

)
}

export default Home
```

### `@apollo/client` version

^3.13.8

### Apollo Client Devtools version
4.18.15 (Firefox)

Contributor guide

Open the contributing guide

Research direction

Start with the supplied Apollo client setup and the Next.js Home component, using @apollo/client ^3.13.8 and Apollo Client Devtools 4.18.15 in Firefox. Reproduce a page refresh with connectToDevTools enabled and verify that the devtools reconnects to the Apollo client afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, next.js, typescript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.