Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@freshsqueezed/mammothgql
Advanced tools
@freshsqueezed/mammothgql
express
Mammoth GQL enables the ability to run your GraphQL middleware as part of an app built with Express, one of the most popular web frameworks for Node.
First, install MammothGQL Middleware, the JavaScript implementation of the core GraphQL algorithms, Express, and two common Express middleware packages:
npm install @freshsqueezed/mammothgql graphql @graphql-tools/schema express cors
Then, write the following to ./src/app.ts
.
import express, { json } from 'express';
import cors from 'cors';
import mammoth from '@freshsqueezed/mammothgql';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { ServerContext } from './types';
const schema = makeExecutableSchema({
typeDefs: `#graphql
type Query {
hello(s: String!): String
}
`,
resolvers: {
Query: {
hello: (_: never, { s }: { s: string }) => s,
},
},
});
const app = express();
app.use(cors());
app.use(json());
app.use(
'/graphql',
mammoth<ServerContext>({
schema,
context: ({ req }) => ({
user: req.user || null,
}),
}),
);
export default app;
Create a ./src/index.ts
file and
import { createServer } from 'node:http';
import app from './app';
const httpServer = createServer(app);
httpServer.listen(3000, () => {
console.log(`
🚀 Server is running on http://localhost:${PORT}/graphql
`);
});
Now run your server with:
ts-node ./src/index.ts
Open the URL it prints in a web browser. It will show GraphiQL, a web-based tool for running GraphQL operations. Try running the operation query { hello }
!
FAQs
GraphQL middleware for express framework
The npm package @freshsqueezed/mammothgql receives a total of 90 weekly downloads. As such, @freshsqueezed/mammothgql popularity was classified as not popular.
We found that @freshsqueezed/mammothgql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.