
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@dashdot/graphql-server
Advanced tools
A simple high performance graphql handler using the power of JIT.
Inside your Node project directory, run the following:
npm i --save @dashdot/graphql-server
Or with Yarn:
yarn add @dashdot/graphql-server
import { createServer } from 'http'
import {
GraphqlQueryStore,
createGraphqlRequestHandler
} from '@dashdot/graphql-server'
import schema from './schema'
const { PORT, HOST } = process.env
const store = new GraphqlQueryStore(schema)
const server = createServer(
createGraphqlRequestHandler(store)
)
server.listen(PORT, HOST, () => {
console.log(`Server started and listening on http://${HOST}:${PORT}`)
})
Dashdot Graphql Server is a simple graphql request processor designed to be framework agnostic. You can use it either with the default Node http server or implement it in your own framework. The library exposes 2 main functions:
Where createGraphqlRequestHandler is just an implementation of processGraphqlRequest using the native Node http package.
What do these functions do? As little as possible. We designed this library to reduce the overhead provided by other libraries. The library processes and validates a Graphql request and passes it to your schema to be interpreted. In sequence here are the steps that are taken:
You schema is not passed directly to the request handler, instead we pass it to a GraphqlQueryStore. The query store wil use the power of JIT (just-in-time compilation) to improve the query performance. You can read more about this here.
export default function processGraphqlRequest(
req: IncomingMessage,
options: ProcessGraphqlRequestOptions
): Promise<GraphqlResponse>;
type ProcessGraphqlRequestOptions = {
store: GraphqlQueryStore
context: any
processFileUploads?: (req: IncomingMessage) => Promise<any>
readRequestBody: (req: IncomingMessage) => Promise<any>
}
type GraphqlResponse = {
status: number
text?: string
body?: any
}
While we try to minimize the overhead of this library it offers basic protection against query complexity attacks using the graphql-query-complexity package. You can customize this basic config by setting the defaultComplexity and maximumComplexity complexity options for the GraphqlQueryStore. You can also extend the validation rules by providing your own custom rules as validationRules option.
type QueryComplexityOptions = {
maximumComplexity?: number
defaultComplexity?: number
}
type GraphqlQueryStoreOptions = {
validationRules?: [ValidationRule]
queryComplexity?: QueryComplexityOptions
}
class GraphqlQueryStore {
constructor(
schema: GraphQLSchema,
options?: GraphqlQueryStoreOptions
) {}
}
By using the processGraphqlRequest function. This function takes a request (like) object and some options to process the graphql request Below you can find an example of an implementation in Next.js and Express.
Example Next.js
// /api/graphql/route.js
import type { NextRequest } from 'next/server'
import { GraphqlQueryStore, processGraphqlRequest } from '@dashdot/graphql-server'
import { createSchema } from './createSchema'
import { createRequestContext } from './requestContext'
const schema = createSchema()
const store = new GraphqlQueryStore(schema)
export async function POST(req: NextRequest) {
try {
const { status, text, body } = await processGraphqlRequest(req, {
store,
context: createRequestContext(req),
readRequestBody: () => req.json(),
})
if (text) {
return new Response(text, { status })
}
if (body) {
return Response.json(body, { status })
}
} catch (e) {
return new Response(e.message, { status: 500 })
}
}
Example Express
// graphql.js
import {
GraphqlQueryStore,
processGraphqlRequest,
} from '@dashdot/graphql-server'
import { createSchema } from './createSchema'
import { createRequestContext } from './requestContext'
import app from './app'
const schema = createSchema()
const store = new GraphqlQueryStore(schema)
app.post('/api/graphql', async (req, res) => {
try {
const { status, text, body } = await processGraphqlRequest({
store,
context: createRequestContext(req),
readRequestBody: async () => {
// Assuming you're using bodyParser or similar middleware
return req.body
},
})
if (text) {
res.status(status).send(text)
} else if (body) {
res.status(status).json(body)
}
} catch (e) {
res.status(500).send(e.message)
}
})
FAQs
A high performance graphql handler using the power of JIT.
The npm package @dashdot/graphql-server receives a total of 86 weekly downloads. As such, @dashdot/graphql-server popularity was classified as not popular.
We found that @dashdot/graphql-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.