Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
1import { useQuery } from 'urql'; 2import { graphql } from './gql'; 3// @ts-expect-error 4import { Pokemon } from './fragment'; 5import * as React from 'react'; 6 7const PokemonQuery = graphql(` 8 query Po($id: ID!) { 9 pokemon(id: $id) { 10 id 11 fleeRate 12 ...pokemonFields 13 attacks { 14 special { 15 name 16 damage 17 } 18 } 19 weight { 20 minimum 21 maximum 22 } 23 name 24 __typename 25 } 26 } 27`); 28 29const Pokemons = () => { 30 const [result] = useQuery({ 31 query: PokemonQuery, 32 variables: { id: '' } 33 }); 34 35 // Works 36 const { fleeRate } = result.data?.pokemon || {}; 37 console.log(fleeRate) 38 // @ts-expect-error 39 const { pokemon: { weight: { minimum } } } = result.data || {}; 40 console.log(minimum) 41 42 // Works 43 const { pokemon } = result.data || {}; 44 console.log(pokemon?.weight?.maximum) 45 46 // @ts-expect-error 47 return <Pokemon data={result.data?.pokemon} />; 48} 49