question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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...

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
juank11memphiscommented, Nov 12, 2018

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…

0reactions
abernixcommented, 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: https://github.com/graphql/graphql-js/pull/1120.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating with Node.js middleware - Apollo GraphQL Docs
When integrating with middleware, first you initialize Apollo Server just like you always do, and then you call applyMiddleware .
Read more >
Authorization with GraphQL Shield - YouTube
In this video we'll explore some of the logic and input rules that come with GraphQL Shield to protect against unwanted requests.
Read more >
apollo-server | Yarn - Package Manager
Getting started. To get started with Apollo Server: Install with npm install apollo-server-<integration> graphql; Write a GraphQL schema; Use one of the ...
Read more >
Secure Your React and Redux App with JWT Authentication
Use Redux middleware to make secure calls to an API. ... Since all data flow is strictly one-way, and because data is never...
Read more >
GraphQL.Server.Transports.AspNetCore 7.2.0 - NuGet
Referencing the "all" package will include the UI middleware packages. These packages depend on GraphQL version 7.0.0 or later. Then update your Program.cs ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found