graphql-js - 无法使用重复的 "graphql"模块

标签 graphql-js

我发现 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/

相关文章:

node.js - 如何为嵌套对象或同一父对象中的对象列表定义 GraphQLObjectType

sequelize.js - self._expandAttributes 不是函数

javascript - 如何将变量从一个 JS 文件传递​​到另一文件中的查询?

graphql - 编译后的代码中遗留了 Gatsby 查询

graphql - 在 GraphQL 中的输入和类型之间共享公共(public)字段

javascript - 如何在 GraphQL 中返回一组对象,可能使用与返回单个对象的端点相同的端点?

mongodb - 在 vanilla GraphQL 中实现分页

graphql - graphql中resolver函数不同实现的解释

graphql-js - 在 GraphQL 中,如何指定嵌套数组作为字段类型?

javascript - 使用Facebook的DataLoader传递参数