-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
282cb2c
commit e6ffbca
Showing
6 changed files
with
96 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
/* eslint-env node, es6*/ | ||
|
||
const path = require('path') | ||
|
||
const fs = require('fs-extra') | ||
|
||
const REDWOOD_PROJECT_DIRECTORY = process.argv.slice(2)[0] | ||
|
||
function main() { | ||
// Copy over SDL | ||
fs.copyFileSync( | ||
path.join('.', 'templates', 'benchmark.sdl.ts'), | ||
path.join( | ||
REDWOOD_PROJECT_DIRECTORY, | ||
'api', | ||
'src', | ||
'graphql', | ||
'benchmark.sdl.ts' | ||
) | ||
) | ||
|
||
// Copy over the service | ||
const benchmarkServicePath = path.join( | ||
REDWOOD_PROJECT_DIRECTORY, | ||
'api', | ||
'src', | ||
'services', | ||
'benchmarks' | ||
) | ||
fs.mkdirSync(benchmarkServicePath) | ||
fs.copyFileSync( | ||
path.join('.', 'templates', 'benchmarks.ts'), | ||
path.join(benchmarkServicePath, 'benchmarks.ts') | ||
) | ||
|
||
// Set DISABLE_CONTEXT_ISOLATION=1 | ||
const dotEnvPath = path.join(REDWOOD_PROJECT_DIRECTORY, '.env') | ||
const dotEnvFile = fs.readFileSync(dotEnvPath, 'utf8') | ||
fs.writeFileSync(dotEnvPath, `${dotEnvFile}\nDISABLE_CONTEXT_ISOLATION=1\n`) | ||
} | ||
main() |
8 changes: 8 additions & 0 deletions
8
tasks/benchmark/setups/default_unsafe_context/templates/benchmark.sdl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const schema = gql` | ||
type MagicNumber { | ||
value: Int! | ||
} | ||
type Mutation { | ||
magicNumber(value: Int!): MagicNumber! @skipAuth | ||
} | ||
` |
27 changes: 27 additions & 0 deletions
27
tasks/benchmark/setups/default_unsafe_context/templates/benchmarks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { MutationResolvers } from 'types/graphql' | ||
|
||
import { setContext } from '@redwoodjs/graphql-server' | ||
|
||
import { logger } from 'src/lib/logger' | ||
|
||
export const magicNumber: MutationResolvers['magicNumber'] = async ({ | ||
value, | ||
}) => { | ||
setContext({ | ||
// ...context, | ||
magicNumber: value, | ||
}) | ||
// context.magicNumber = value | ||
|
||
const sleep = Math.random() * 200 | ||
// logger.info(`Sleeping for ${sleep}ms`) | ||
await new Promise((resolve) => setTimeout(resolve, sleep)) | ||
|
||
const numberFromContext = (context.magicNumber ?? -1) as number | ||
if (value !== numberFromContext) { | ||
logger.error(`Expected ${value} but got ${numberFromContext}`) | ||
// throw new Error(`Expected ${value} but got ${numberFromContext}`) | ||
} | ||
|
||
return { value: numberFromContext } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters