重复的"graphql"不能使用模块 [英] Duplicate "graphql" modules cannot be used
问题描述
我发现 graphql-js 库不允许依赖项也使用graphql.
I have found that the graphql-js library does not allow dependencies to also use graphql.
您将收到以下错误
重复的"graphql"模块不能同时使用,因为不同版本可能具有不同的功能和行为.来自一个的数据在另一个函数中使用的版本可能会产生混淆,并且虚假结果.
来自以下代码
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { GraphQLSchema } = require('graphql');
// the module graphql-test-mod-obj-type' has
// graphql as a depenedency
const myType = require('graphql-test-mod-obj-type');
const app = express();
const schema = new GraphQLSchema({ query: myType })
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true
}));
app.listen(4000);
我创建了一个小型的repo和一个小型的公共npm软件包来演示这一点 repo-with-npm-dependency-on-graphql
I created a small repo and a small public npm package to demonstrate this repo-with-npm-dependency-on-graphql .
通过不使用graphql模块作为模块中的依赖项,可以很容易地解决此问题.但这肯定是一个问题吗?还是这是众所周知的事情?
This can be quite easily worked around by not having the graphql module as a dependency in the module. But surely this is an issue? Or is this a well known thing?
推荐答案
it does appear that this is a longstanding and known issue and is covered here
这篇关于重复的"graphql"不能使用模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!