node.js - typeDefs 必须只包含字符串、文档、模式或函数,得到对象
问题描述
我正在开发一个 express apollo 服务器,并构建了所有 graphql 类型,如下所示:
我正在使用“graphql-tools/load-files”和“graphql-tools/merge”来合并所有类型。我的 index.js 文件如下所示:
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const types = loadFilesSync(path.join(__dirname, '.'), { recursive: true })
const typeDefs = mergeTypeDefs(types);
module.exports = { typeDefs };
当我运行我的项目时,出现以下错误:
Error: typeDefs must contain only strings, documents, schemas, or functions, got object
该代码在以前的项目中正常工作。但是当我开始一个新项目删除以前的节点模块和新的 npm 安装时,我遇到了这个奇怪的问题。我怎样才能摆脱它?
解决方案
我找到了解决问题的方法。我不得不删除 { recursive: true } 并添加 { extensions: ['gql'] 。这里是:
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const typesArray = loadFilesSync(path.join(__dirname, '.'), { extensions: ['gql'] });
const typeDefs = mergeTypeDefs(types);
module.exports = { typeDefs };
推荐阅读
- typescript - 如何访问接口的构造函数类型?
- android - NavigationAdapter 使用两个图标
- angular - 角度复选框值
- javascript - 如何从 Nodejs 环境发送 JS 文件以供客户端使用?
- flutter - ImageSource.Gallery 上带有抖动的图像选择器的错误
- jboss - 域模式下的 Keycloak JBoss EAP7 适配器
- sql - 每天每个状态的 PostgreSQL 计数
- haproxy - 如何从 haproxy 中的 req.uri 中删除开头的斜杠
- javascript - 是否可以“创建”对象的属性?
- php - PHP Curl 和 OData