问题描述
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()]
}),],})
我指的是这个包: https://www.npmjs.com/package/graphql-constraint-directive。
我在实现它后在我的控制台上加载类型时遇到此错误:
Error: Directive "constraint" may not be used on ARGUMENT_DEFinitioN.
如何在架构级别应用验证?
解决方法
您的问题是您正在尝试使用 apollo-server-express 中的 makeExecutableSchema。
如 docs 中所述,应使用 graphql-tools 中的 makeExecutableSchema。
解决方案:
const { ApolloServer } = require('apollo-server-express')
const { makeExecutableSchema } = require('graphql-tools')