Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues wrapping middleware around schema, with applyMiddleware #216

Closed
NeutronScott12 opened this issue Dec 14, 2018 · 2 comments
Closed

Comments

@NeutronScott12
Copy link

NeutronScott12 commented Dec 14, 2018

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.

Here is the resolver and middleware in question

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
	}
);
async getProfile(
			_: any,
			{ username }: any,
			{ db }: Context,
			info: any
		) {
			try {
				console.log('PROFILE');
				const profile: User | null = await db.query.user(
					{ where: { username } },
					info
				);

				if (!profile) {
					return new ApolloError('No such user');
				}

				console.log('PROFILE', profile);

				return profile;
			} catch (error) {
				logger.error({ level: '5', message: error });
				return error;
			}
		}

And I am using apollo-express-server.

@maticzav
Copy link
Owner

Hey @OGNeutron 👋,

could you use one of the templates for creating an issue? For the reference, I believe this is connected to maticzav/graphql-middleware#75 and apollographql/apollo-server#1935

@NeutronScott12
Copy link
Author

I created a new issue using one of the templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants