我发现 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);
我创建了一个小型 repo 和一个小型公共(public) npm 包来演示这一点
repo-with-npm-dependency-on-graphql .
通过不将 graphql 模块作为模块中的依赖项,可以很容易地解决这个问题。但这肯定是个问题吗?或者这是众所周知的事情?
最佳答案
看来这是一个长期存在的已知问题,并已涵盖 here
关于graphql-js - 无法使用重复的 "graphql"模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53252347/