Skip to content

skipToken support for typescript-react-apollo #647

@Moeface

Description

@Moeface

skip as an option for suspense hooks is going to be deprecated in favour of a new skipToken technique in an upcoming version of Apollo, as it provides more type safety.

Apollo docs on skip:

This option is deprecated and only supported to ease the migration from useQuery. It will be removed in a future release. Please use skipToken instead of the skip option as it is more type-safe.

More reading:

You can work around this at the moment by using useSuspenseQuery directly from @apollo/client and using the document and types generated by graphql-code-generator, eg:

import { useSuspenseQuery, skipToken } from '@apollo/client'
import { ExampleQueryResult, ExampleQueryDocument } from './generated'`

const { data } = useSuspenseQuery<ExampleQueryResult>(
    ExampleQueryDocument,
    id ? { variables: { id } } : skipToken
  )

Describe the solution you'd like

It would great if the generated suspense hook had native support for this (which aligns with what their docs recommend), eg:

import { skipToken } from '@apollo/client'
import { useExampleSuspenseQuery } from './generated'`

const { data } = useExampleSuspenseQuery(id ? { variables: { id } } : skipToken)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions