Graphql-shield: Having issues with applying middleware to schema.

Created on 14 Dec 2018  路  4Comments  路  Source: maticzav/graphql-shield

Bug report

  • [ x] I have checked other issues to make sure this is not a duplicate.

Describe the bug

Well, every time I try to include some middle-ware I get an error warning about sync and asynchronous wrapping, this wasn't an issue until I updated the below packages.

To Reproduce

Well, I've installed the latest apollo-express-server(2.3.1), graphql(14.0.2), graphql-middleware(2.0.2) and graphql-shield(4.1.2), and I precede to create some middle-ware functions but get the below error.

import { rule, shield } from 'graphql-shield';
import { Context } from '../../../tstypes';

const isAuthenticated = rule()(
    async (_: any, __: any, { session }: Context, ___: any) => !!session.userId
);

export const ShieldMiddleware = shield(
    {
        Query: {
            getProfile: isAuthenticated
        }
    },
    {
        debug: true,
        graphiql: true
    }
);

And then I precede to apply those to the schema

const typeDefs: string = importSchema(path.join(__dirname, './schema.graphql'));

const makeSchema = makeExecutableSchema({
    typeDefs,
    resolvers: genResolvers(path.join(__dirname, '/**/resolvers.?s'))
});

const { schema } = applyMiddleware(makeSchema, ShieldMiddleware);

And then apply it to the apollo-express-server

const server: ApolloServer = new ApolloServer({
    subscriptions: {
        path: '/graphql'
    },
    schema,
});

Expected behavior

And I expect it to do as intended.

Actual behaviour

Error: The introspection query is resolving asynchronously; execution of an introspection query is not expected to return a Promise.

Wrapped type resolvers should maintain the existing execution dynamics of the resolvers they wrap (i.e. async vs sync) or introspection types should be excluded from wrapping by checking them with graphql/types, isIntrospectionType predicate function prior to wrapping.

Additional context

I hope this is what you meant when you asked me to create a new issue using a template 馃憤

Most helpful comment

:tada: This issue has been resolved in version 5.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

All 4 comments

Any luck with finding the issue?

@OGNeutron can you try with graphql-middleware version 3?

It seems that this package should update graphql-middleware in it's dependencies. Just tested with latest versions of graphql-shield and graphql-middleware, and error is still there. Other middlewares now works correctly.
Pinging @maticzav

:tada: This issue has been resolved in version 5.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings