Skip to content

Commit

Permalink
feat: add apollo graphql armor (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiemanshu authored Jul 12, 2023
1 parent 3cee1d8 commit 36a79c9
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@apollo/client": "^3.4.16",
"@babel/runtime": "^7.9.2",
"@babel/runtime-corejs3": "^7.9.2",
"@escape.tech/graphql-armor": "^1.4.0",
"@google-cloud/storage": "^5.7.4",
"@graphql-tools/mock": "^8.4.0",
"@graphql-tools/schema": "^8.2.0",
Expand Down
11 changes: 10 additions & 1 deletion src/server/routes/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable import/prefer-default-export */
import { ApolloArmor } from "@escape.tech/graphql-armor";
import { addMocksToSchema } from "@graphql-tools/mock";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
Expand Down Expand Up @@ -49,6 +50,13 @@ export const createRouter = async () => {
return err;
};

const armor = new ApolloArmor({
maxDepth: {
n: 10
}
});
const protection = armor.protect();

const plugins = config.isProduction
? []
: [ApolloServerPluginLandingPageGraphQLPlayground()];
Expand All @@ -58,7 +66,8 @@ export const createRouter = async () => {
formatError,
debug: !config.isProduction,
introspection: !config.isProduction,
plugins,
...protection,
plugins: [...protection.plugins, ...plugins],
context: async ({ req }) => contextForRequest(req)
});

Expand Down
Loading

0 comments on commit 36a79c9

Please sign in to comment.