Add out of the box support for GraphQL Middleware plugins.
@maticzav do you have an example of the "workaround" for this?
@notrab yeah, you can use it with makeExecutableSchema and then applyMiddleware like this;
const schema = makeExecutableSchema({ typeDefs, resolvers })
const schemaWithMiddleware = applyMiddleware(
schema,
metricsMiddleware,
authMiddleware,
beepMiddleware,
)
I believe it would be a lot more convenient though to have general support for it. I will try to make a PR in the coming days!
https://github.com/prisma/graphql-middleware#standalone-usage
Awesome thanks @maticzav - it's been a while since I looked at graphql-middleware. Great to see it's taking shape!
Hello guys,
How do you make it work when you pass your resolvers and schemas in the server constructor ?
for the moment I build my server like this :
import { importSchema } from 'graphql-import';
import resolvers from './resolvers';
const typeDefs = importSchema('./schema.graphql'));
const server = new ApolloServer({
mocks: false,
resolvers,
typeDefs
});
Hey @Alvyre 馃憢
Since we still haven't implemented this, you could use the alternative approach we mentioned above. Instead of supplying resolvers and typeDefs to server directly you can provide a schema that you build upfront. Something like this;
const schema = makeExecutableSchema({ typeDefs, resolvers })
const schemaWithMiddleware = applyMiddleware(
schema,
metricsMiddleware,
authMiddleware,
beepMiddleware,
)
const server = new ApolloServer({
mocks: false,
schema: schemaWithMiddleware,,
});
You can find even more information about it in the link below. I hope this helps you solve the problem; I will try to make a PR by the end of the week 馃
https://github.com/prisma/graphql-middleware#standalone-usage
Thank you for you reply and for the example. It works!
I'm waiting for your PR :+1:
Thank you for your work by the way!
Closing this, see https://github.com/apollographql/apollo-server/pull/1799#issuecomment-448545801.
I am having an issue with makeExecutableSchema, where I get "Error: Unknown directive "@cacheControl". This is a built in directive from apollo.
Most helpful comment
Hey @Alvyre 馃憢
Since we still haven't implemented this, you could use the alternative approach we mentioned above. Instead of supplying
resolversandtypeDefstoserverdirectly you can provide a schema that you build upfront. Something like this;You can find even more information about it in the link below. I hope this helps you solve the problem; I will try to make a PR by the end of the week 馃
https://github.com/prisma/graphql-middleware#standalone-usage