【问题标题】:Error: Directive constraint in Graphql yoga when using constraints错误:使用约束时 Graphql 瑜伽中的指令约束
【发布时间】:2019-09-28 09:29:43
【问题描述】:

我正在使用带有 Prisma 的 Graphql 服务器。但是当我尝试运行代码时出现此错误 我正在使用

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
   )

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

【问题讨论】:

    标签: node.js graphql apollo


    【解决方案1】:

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

    directive @constraint(
      maxLength:Int!
    ) on FIELD_DEFINITION
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-16
      • 2019-12-30
      • 2018-03-11
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多