Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Cost Analyzer #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/base/express/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const bodyParser = require('body-parser')
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express')
const { SubscriptionServer } = require('subscriptions-transport-ws')
const { execute, subscribe } = require('graphql')
const costAnalysis = require('graphql-cost-analysis').default
const { pubsub } = require('../lib/RedisPubSub')
const cookie = require('cookie')
const cookieParser = require('cookie-parser')
Expand Down Expand Up @@ -70,13 +71,23 @@ module.exports = (
)

const graphqlMiddleware = graphqlExpress((req) => {
const costAnalyzer = costAnalysis({
maximumCost: 100000,
defaultCost: 10,
onComplete(cost, ...rest) {
if (req && req.body) {
console.log(`cost-analysis / ${req.body.operationName}: ${cost}`)
}
}
});
return {
debug: false,
formatError: (error) => {
console.error('error in graphql', error)
return error
},
schema: executableSchema,
validationRules: [ costAnalyzer ],
context: createContext({
user: req.user,
req
Expand Down
1 change: 1 addition & 0 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"d3-time-format": "^2.1.1",
"export-files": "^2.1.1",
"express": "^4.16.2",
"graphql-cost-analysis": "^0.1.1",
"graphql-redis-subscriptions": "^1.4.0",
"graphql-subscriptions": "^0.5.6",
"pogi": "^2.5.5",
Expand Down
35 changes: 34 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"

brackets2dots@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/brackets2dots/-/brackets2dots-1.1.0.tgz#3f3d40375fc660ce0fd004fa27d67b34f9469ac3"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
Expand Down Expand Up @@ -1114,6 +1118,12 @@ currently-unhandled@^0.4.1:
dependencies:
array-find-index "^1.0.1"

curry2@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/curry2/-/curry2-1.0.3.tgz#38191d55f1060bfea47ca08009385bb878f6612f"
dependencies:
fast-bind "^1.0.0"

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2"
Expand Down Expand Up @@ -1239,7 +1249,7 @@ debug-log@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"

debug@2, [email protected], debug@^2.1.1, debug@^2.2.0, debug@^2.6.8:
debug@2, [email protected], debug@^2.1.1, debug@^2.2.0, debug@^2.5.2, debug@^2.6.8:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
dependencies:
Expand Down Expand Up @@ -1398,6 +1408,10 @@ dotenv@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"

dotsplit.js@^1.0.3:
version "1.1.0"
resolved "https://registry.yarnpkg.com/dotsplit.js/-/dotsplit.js-1.1.0.tgz#25a239eabe922a91ffa5d2a172d6c9fb82451e02"

double-ended-queue@^2.1.0-0:
version "2.1.0-0"
resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c"
Expand Down Expand Up @@ -1856,6 +1870,10 @@ [email protected]:
version "0.1.8"
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"

fast-bind@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-bind/-/fast-bind-1.0.0.tgz#7fa9652cb3325f5cd1e252d6cb4f160de1a76e75"

fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"
Expand Down Expand Up @@ -2378,6 +2396,12 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

graphql-cost-analysis@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/graphql-cost-analysis/-/graphql-cost-analysis-0.1.1.tgz#e500cb2e896efe333f6912bb264ccb7948a6c06a"
dependencies:
selectn "^1.1.2"

graphql-extensions@^0.0.x:
version "0.0.5"
resolved "https://registry.yarnpkg.com/graphql-extensions/-/graphql-extensions-0.0.5.tgz#63bc4a3fd31aab12bfadf783cbc038a9a6937cf0"
Expand Down Expand Up @@ -5006,6 +5030,15 @@ samsam@~1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.3.tgz#9f5087419b4d091f232571e7fa52e90b0f552621"

selectn@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/selectn/-/selectn-1.1.2.tgz#fc8acd91df3f45acb01891c6773ae529851d6b17"
dependencies:
brackets2dots "^1.1.0"
curry2 "^1.0.0"
debug "^2.5.2"
dotsplit.js "^1.0.3"

semantic-release@^6.3.1, semantic-release@^6.3.6:
version "6.3.6"
resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-6.3.6.tgz#629d0aec90b38a2957a57a4a9ee1214af51928c7"
Expand Down