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

Unable to use applyMiddleware (from graphql-middleware) after upgrading to 2.2.0 #1934

Closed
hinsxd opened this issue Nov 8, 2018 · 13 comments
Closed

Comments

@hinsxd
Copy link

hinsxd commented Nov 8, 2018

With a minimum graphql server with express, apollo-server 2.2.0 throws Error: Unable to generate server introspection document. while trying to apply middleware (graphql-shield) on the server with graphql-middleware

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

const typeDefs = `
	type Query {
		me: String!
	}

	type Mutation {
		test: String!
	}
`;
const resolvers = {
	Query: {
		me: () => 'me'
	},
	Mutation: {
		test: () => 'hi'
	}
};

const permissions = shield({
	Query: {
		me: true
	},
	Mutation: {
		test: true
	}
});

const schema = applyMiddleware(
	makeExecutableSchema({ typeDefs, resolvers }),
	permissions
);
const server = new ApolloServer({
	mocks: false,
	schema,
	context: ({ req }) => ({
		...req
	})
});
const app = express();
server.applyMiddleware({ app, path: '/graphql' });
app.listen({ port: 4000 }, () => {
	console.log(`🚀 Server ready at http://localhost:4000`);
});

which gives the following error:

/Users/hinsxd/projects/askmrfox/test/node_modules/apollo-server-core/dist/utils/schemaHash.js:16
        throw new Error('Unable to generate server introspection document.');
        ^

Error: Unable to generate server introspection document.
    at Object.generateSchemaHash (/Users/hinsxd/projects/askmrfox/test/node_modules/apollo-server-core/dist/utils/schemaHash.js:16:15)
    at new ApolloServerBase (/Users/hinsxd/projects/askmrfox/test/node_modules/apollo-server-core/dist/ApolloServer.js:157:40)
    at new ApolloServer (/Users/hinsxd/projects/askmrfox/test/node_modules/apollo-server-express/dist/ApolloServer.js:44:1)
    at Object.<anonymous> (/Users/hinsxd/projects/askmrfox/test/src/index.js:38:16)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
[nodemon] app crashed - waiting for file changes before starting...
@Infonautica
Copy link

Same problem. Pinned version "apollo-server": "2.0.5" works great

@wmertens
Copy link
Contributor

wmertens commented Nov 8, 2018

Same problem, but I don't use middlewares.

The problem seems to be that the result of execute(schema, documentAST) is a Promise, but it is not awaited.

@michieldewilde
Copy link
Contributor

Running into this as well

@juank11memphis
Copy link

I am having the same issue, had to downgrade.

Any ideas why is this happening?

@hinsxd
Copy link
Author

hinsxd commented Nov 8, 2018

It is even more weird that, even if I only declare the middleware but not using it in initializing the server, it still shows the error. Any clue?

@wmertens
Copy link
Contributor

wmertens commented Nov 8, 2018

@juank11memphis @hinsxd see #1935 . You can go back to v2.0.5 in the meantime.

@donedgardo
Copy link

Same problem here thanks for the info @wmertens

@dwelch2344
Copy link

Confirmed I'm hitting this too as a result from a promise being rerturned in generateSchemaHash. Thanks for the pinning workaround – spent a good 10 hours digging and learning (which isn't a wash)

@dortamiguel
Copy link
Contributor

Yep, I have the same error

@juank11memphis
Copy link

I tried using version 2.2.1 thinking the problem was going to be fixed, but I am still getting the same error. This should not be a version with breaking changes, I would expect just to update the version and everything to keep working as before...

@juank11memphis
Copy link

Version 2.2.2 still not working, it just shows kind of a better error but not good enough to understand what do we need to do to fix this, and still this is not supposed to be a version with breaking changes, and if it is, a little guide would be more than appreciated.
Thanks.

@dortamiguel
Copy link
Contributor

I think the error comes from here https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/utils/schemaHash.ts#L23

Though, Im not sure what I'm doing wrong, is this type checking my typescript code on execution?

@abernix
Copy link
Member

abernix commented Nov 17, 2018

Closing as a duplicate of #1935. I've responded over there as to the problem, but the short explanation is that the execution of an introspection query, which is not supposed to run asynchronously. The situation occurring here is that resolvers are being wrapped in a way which doesn't maintain their original execution dynamics, thus violating this assumption. See related: graphql/graphql-js#1120.

@abernix abernix closed this as completed Nov 17, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants