Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@freshsqueezed/mammothgql

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@freshsqueezed/mammothgql

GraphQL middleware for express framework

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-61.54%
Maintainers
1
Weekly downloads
 
Created
Source

@freshsqueezed/mammothgql

@freshsqueezed/mammothgql

A TypeScript/JavaScript GraphQL middleware for express

Getting started: Express middleware

Mammoth GQL enables the ability to add middleware that lets you run your GraphQL server 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 @afreshsqueezed/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 { ServerContext } from './types';
import schema from './graphql';

const app = express();

app.use(cors());
app.use(json());
app.use(
  '/graphql',
  mammoth<ServerContext>({
    schema,
    graphiql: true,
    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 }!

Keywords

FAQs

Package last updated on 26 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc