Ad

Error: Directive Constraint In Graphql Yoga When Using Constraints

- 1 answer

I am using Graphql server with Prisma. but when i try to run the code i get this error I am using

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

This is the error

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)

I tried to remove the constraint from the datamodel but the error persists

@constraint(
   maxLength:650,
   minLength:20
   )

has anyone got the same or similar error ? Thanks

Ad

Answer

I found the solution for this problem Finally it was a typing problem, the directive was not declared and so not recognized by graphql-yoga so I added the declaration of the directive in the schema.graphql file which contains the declaration of all Entities and it worked

directive @constraint(
  maxLength:Int!
) on FIELD_DEFINITION

So here the graphql-yoga can find the Directive. Hope that will help you I don't know exactly how it works from inside but it solved my problem

Ad
source: stackoverflow.com
Ad