如何在Apollo Server v4中导入gql以创建类型定义?
Apollo Server v4 中正确导入gql的方法
Apollo Server v4 已将gql标签从核心包@apollo/server中拆分,需通过独立包graphql-tag来使用:
- 安装依赖
执行以下命令安装graphql-tag:
npm install graphql-tag # 或使用yarn yarn add graphql-tag
- 正确导入并使用
替换原导入语句,直接从graphql-tag导入gql:
import gql from 'graphql-tag'; const typeDefs = gql` # 这里编写你的类型定义 type Query { hello: String! } `;
若使用TypeScript,无需额外配置类型,graphql-tag已自带完整的类型声明。
内容的提问来源于stack exchange,提问作者Bikrant
相关产品推荐
相关产品推荐

