我在React和Apollo中使用graphql:generate从graphql模式创建类型。
我还在使用react-apollo-hooks useQuery输出数据。
一切似乎都正常,我可以看到输出的数据
我的问题是我看不到如何声明生成的类型,然后在vc代码中获取intelliSense。
查询
import { gql } from 'apollo-boost';
export const GET_ALL_RECIPES = gql`
query RecipesData{
recipe{
_id
name
description
}
}
`
生成的类型
/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: RecipesData
// ====================================================
export interface RecipesData_recipe {
__typename: "Recipe";
_id: string | null;
name: string | null;
description: string | null;
}
export interface RecipesData {
recipe: (RecipesData_recipe | null)[] | null;
}
App.tsx
import React from 'react';
import './App.css';
import { useQuery } from 'react-apollo-hooks';
import { GET_ALL_RECIPES } from '../queries';
import { RecipesData_recipe } from '../generated/RecipesData';
const App: React.FC<RecipesData> = () => {
const { data, loading } = useQuery(GET_ALL_RECIPES, {
suspend: false
})
if (loading || !data) return <div>Loading</div>
return (
<ul>
{data.recipe.map((recipe) =>
<li key={recipe._id}>{recipe.name}</li>
)}
</ul>
);
}
export default App;
我如何正确地在App.tsx中声明RecipesData
或RecipesData_recipe
以对recipe.name
使用intelliSense