node.js - 错误: Directive constraint in Graphql yoga when using constraints

标签 node.js graphql apollo

我正在将 Graphql 服务器与 Prisma 一起使用。但是当我尝试运行代码时出现此错误 我正在使用

const { GraphQLServer } = require('graphql-yoga')
const { prisma } = require('./generated/prisma-client')  

这是错误

Error: Directive constraint: Couldn't find type constraint in any of the schemas.
at collectDirective (D:\project\Starter\server\node_modules\graphql-import\dist\definition.js:113:23)
at Array.forEach (<anonymous>)
at collectNode (D:\project\Starter\server\node_modules\graphql-import\dist\definition.js:105:25)
at D:\project\Starter\server\node_modules\graphql-import\dist\definition.js:87:13
at Array.forEach (<anonymous>)
at collectNewTypeDefinitions (D:\project\Starter\server\node_modules\graphql-import\dist\definition.js:86:30)
at Object.completeDefinitionPool (D:\project\Starter\server\node_modules\graphql-import\dist\definition.js:23:41)
at Object.importSchema (D:\project\Starter\server\node_modules\graphql-import\dist\index.js:99:67)
at mergeTypeDefs (D:\project\Starter\server\node_modules\graphql-yoga\dist\index.js:420:37)
at new GraphQLServer (D:\project\Starter\server\node_modules\graphql-yoga\dist\index.js:95:34)

我尝试从数据模型中删除约束,但错误仍然存​​在

@constraint(
   maxLength:650,
   minLength:20
   )

有人遇到相同或类似的错误吗? 谢谢

最佳答案

我找到了这个问题的解决方案 最后,这是一个打字问题,该指令未声明,因此无法被 graphql-yoga 识别,因此我在 schema.graphql 文件中添加了该指令的声明,该文件包含所有实体的声明,并且它有效

directive @constraint(
  maxLength:Int!
) on FIELD_DEFINITION

所以这里 graphql-yoga 可以找到指令。 希望对您有帮助 我不知道它内部是如何工作的,但它解决了我的问题

关于node.js - 错误: Directive constraint in Graphql yoga when using constraints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56078152/

相关文章:

mysql - 如何在Sequelize中的belongsToMany关系中包含模型

javascript - NodeJS本地存储获取值

javascript - 映射中的 Object.assign 返回带有额外信息的意外响应

arrays - Golang 从 postgresql 函数获取值,该函数返回一个 int 但也接收一个字符串数组

typescript - 您如何模拟 Apollo Server RESTDataSource 以使用 Jest 进行单元测试?

angularjs - 当用户在 nodeJS/Express 和 Angular 中闲置一段时间(基于 token 的授权)时,我如何使我的 JWT token 过期

node.js - 使用单个服务器将 GraphQL 订阅添加到现有的 Express 应用程序

graphql - 我应该一遍又一遍地重新输入我的字段,还是我认为这是错误的?

javascript - 为什么我无法使用 Apollo Link State 添加待办事项?

angular - 服务中的 Apollo GraphQL 查询重复集合项?