new MiddlewareError(`Type ${type} exists in middleware but is missing in Schema.`);
kamarajuPrathi opened this issue ยท comments
I am using graphql shield with apollo-server-lambda,graphql-middleware,graphql-tools when i apply permission to applymiddleware i get the above error
Followed the same steps as in your example
Hey @kamarajuPrathi ๐,
Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.
https://opencollective.com/graphql-shield
PS.: We offer
priority
support for all financial contributors. Don't forget to addpriority
label once you start contributing ๐
Can some one look in to it , its little urgent @maticzav
@kamarajuPrathi we offer priority
support, you know ๐ . You could compose a CodeSandbox outlining your problem, and I'll see what I can do. With current information I cannot do anything.
@maticzav basically its missing permissions type from schema . How do we ensure the we get that permissions on the schema ?
I am doing
const { applyMiddleware } = require("graphql-middleware")
const { makeExecutableSchema } = require("graphql-tools")
const { rule, shield } = require("graphql-shield")
const isAuthenticated = rule()(async (parent, args, ctx, info) => {
return ctx.user
})
// Construct a schema, using GraphQL schema language.
let typeDefs = gql
type Query {
hello: String
}
const resolvers = {
Query: {
hello: () => "Hello world!",
},
}
const permissions = shield({
Query: {
hello: isAuthenticated,
},
})
const schema = applyMiddleware(
makeExecutableSchema({
typeDefs,
resolvers,
}),
permissions,
)
const server = new ApolloServer({
schema,
})
exports.graphql = server.createHandler()
The error i am getting from graphql-middleware
import { IMiddleware } from './types'
import { isMiddlewareFunction } from './utils'
export function validateMiddleware<TSource, TContext, TArgs>(
schema: GraphQLSchema,
middleware: IMiddleware<TSource, TContext, TArgs>,
): IMiddleware<TSource, TContext, TArgs> {
if (isMiddlewareFunction(middleware)) {
return middleware
}
const types = schema.getTypeMap()
Object.keys(middleware).forEach(type => {
if (!Object.keys(types).includes(type)) {
throw new MiddlewareError(
`Type ${type} exists in middleware but is missing in Schema.`,
)
}```
@maticzav below are the libraray versions i use
"apollo-server-lambda": "~2.9.16",
"graphql": "~14.5.8",
"graphql-import": "~0.7.1",
"graphql-middleware": "^4.0.2",
"graphql-shield": "^7.0.11"
@kamarajuPrathi Did you solve this?
@joeyfigaro check that you don't have any type mismatches with your dependencies.
Facing the same issue Type ${type} exists in middleware but is missing in Schema..Used graphql-middelware and express-graphql.
Versions
"graphql-shield": "^7.5.0",
"graphql-middleware": "^6.1.4",
"express-graphql": "^0.12.0",
i'm also having the same problem with the same setup, it's throwing an error about no type $ in the Schema:
"graphql-middleware": "^6.1.11",
"graphql-shield": "^7.5.0",
"express-graphql": "^0.12.0"