GraphQl工具LOADFILESSYNC适用于运行时,但在Nodejs中不适合开玩笑 - 为什么?
我正在努力设置Apollo GraphQl Server(基于Express),并使用本指南。这导致我使用loadFileSsync
,path
和提供的节点__ dirname
。
我的Typedefs模块看起来像是这样的,
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const schemaDefsArray = loadFilesSync(
path.join(__dirname, './types'),
{
recursive: true,
extensions: ['graphql'],
})
const typeDefs = mergeTypeDefs(schemaDefsArray);
module.exports = typeDefs;
我的设置是一个由docker容器构建的docker容器,该容器是从返回到Windows中的WSL文件系统的。 Apollo/Express Server和Jest测试均从该容器内部在节点上运行。
我的问题是,在常规运行时(基于Express的Apollo GraphQl Server),__ dirname
是/srv/<项目名称根据预期解决模式。但是在测试运行期间(直接在节点上运行的玩笑)
__ dirname
是完全合格的\\ wsl $ \ ubuntu-20.04 \ home \ home \ home \> user name> \ projects> \ project ; \ src \ schema
。 Apollo服务器加载,读取和解析架构罚款,而开玩笑测试试图通过同一模块加载相同文件的测试找不到目录。
为什么工作目录的解决方案有所不同,这对loadfiles
函数意味着什么?我该如何解决?
I am working on setting up an Apollo GraphQL Server (Express based) and use the pattern where .graphql files are loaded and merged as demonstrated in this guide. This leads me to use loadFilesSync
, path
and the Node provided __dirName
.
My typedefs module looks like this
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const schemaDefsArray = loadFilesSync(
path.join(__dirname, './types'),
{
recursive: true,
extensions: ['graphql'],
})
const typeDefs = mergeTypeDefs(schemaDefsArray);
module.exports = typeDefs;
My setup is a docker container built from a repo checked out to the WSL file system in Windows. Both the Apollo/Express server and Jest tests are run on Node from inside that container.
My problem is that during regular runtime (Express based Apollo GraphQL Server), __dirName
is /srv/<project name>/src/schema
and all .graphql-files are resolved for the schema as intended. But during test-runs (Jest running directly on Node) __dirName
is a fully qualified \\wsl$\Ubuntu-20.04\home\<user name>\projects\<project name>\src\schema
. The Apollo Server loads, reads, and resolves the schema fine while Jest tests attempting to load the same files through the same module cannot find the directory.
Why is the working directory resolved differently, what does it mean for the loadFiles
function and how do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论