我发现graphql-js库不允许依赖项也使用graphql。
您将收到以下错误
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
来自以下代码
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);
我创建了一个小型存储库和一个小型公共npm软件包来演示此操作 repo-with-npm-dependency-on-graphql。
通过不使用graphql模块作为模块中的依赖项,可以很容易地解决此问题。但这肯定是一个问题吗?还是这是众所周知的事情?