How to apply validation in graphQL schema using graphql-constraint-directive

766 Views Asked by At
import { ApolloServer, makeExecutableSchema } from 'apollo-server-express';
const { constraintDirective, constraintDirectiveTypeDefs } = require('graphql-constraint-directive');

schema: mergeSchemas({
  schemas: [
    makeExecutableSchema({
      resolvers: resolver,
      typeDefs: [constraintDirectiveTypeDefs, typeDefs],
      schemaTransforms: [constraintDirective()]
    }),
  ],
}) 

I am referring this pacakge: https://www.npmjs.com/package/graphql-constraint-directive.

I am getting this error in loading types on my console after implementing it:

Error: Directive "constraint" may not be used on ARGUMENT_DEFINITION.

How to apply validation at schema level?

1

There are 1 best solutions below

0
Wedyarit On

Your problem is that you are trying to use makeExecutableSchema from apollo-server-express.

As stated in the docs, makeExecutableSchema from graphql-tools should be used.

Solution:

const { ApolloServer } = require('apollo-server-express')
const { makeExecutableSchema } = require('graphql-tools')