character plugin without envelop?
migs35323 opened this issue · comments
trying to use this plugin in apollo server,
it is possible to use it without envelop?
the readme only provides usage info with envelop
Hello @migs35323,
Unfortunately this is not possible in its current state.
However, here is how to create a plugin that limit the number of character by using graphql-js
.
import type { GraphQLRequestContext } from 'apollo-server-types';
import { GraphQLError } from 'graphql';
const plugin = (maxLength) => {
return {
async requestDidStart(context: GraphQLRequestContext) {
if (!context.request.query) return;
if (context.request.query.length > maxLength!) {
throw new GraphQLError('Query is too large.', {
extensions: { code: 'BAD_USER_INPUT' },
});
}
},
};
};
By the way, I recommend you to limit using the number of token instead.