open-index/open-npm huggingface dataset:
npm package: @freshsqueezed/apollo-next
Description: Apollo server integration for nextjs framework
Author: Matt Gordon
Latest version: 0.0.10

# `@as-integrations/nextjs`

## A TypeScript/JavaScript GraphQL middleware for `@apollo/server`

## Getting started: Nextjs integration

Apollo Server enables the ability to add middleware that lets you run your GraphQL server as part of an app built with Nextjs, one of the most popular web frameworks for Node.

First, create a new nextjs app (visit nextjs [docs](https://nextjs.org/docs/api-reference/create-next-app) for more options/templates):

```
npx create-next-app@latest
```

Then, install Apollo Server, and the JavaScript implementation of the core GraphQL algorithms packages:

```
npm install @apollo/server graphql
```

Finally, write the following to `./pages/api/graphql.js` to utilize [API Routes](https://nextjs.org/docs/api-routes/introduction) built into the nextjs framework:

```js
import { ApolloServer } from "@apollo/server";
import { startServerAndCreateNextHandler } from "@as-integrations/nextjs";

const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => "world",
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

export default startServerAndCreateNextHandler(server, {
  context: async ({ req }) => ({ token: req.headers.token }),
});
```

Now run your nextjs app with:

```
npm run dev
```

Open the URL it prints in a web browser and visit the `/api/graphql` route. It will show Apollo Sandbox, a web-based tool for running GraphQL operations. Try running the operation `query { hello }`!
npm package: @freshsqueezed/mammothgql
Description: GraphQL middleware for express framework
Author: Matt Gordon
Latest version: 1.0.26

[![@freshsqueezed/mammothgql](https://github.com/freshsqueezed/mammothgql/actions/workflows/release-package.yml/badge.svg)](https://github.com/freshsqueezed/mammothgql/actions/workflows/release-package.yml)

# `@freshsqueezed/mammothgql`

## A TypeScript/JavaScript GraphQL middleware for `express`

## Getting started: Express middleware

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`.

```ts
import express, { json } from 'express';
import cors, { CorsRequest } from 'cors';
import { mammothGraphql } from '@freshsqueezed/mammothgql';
import schema from './graphql';
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<CorsRequest>());
app.use(json());

app.use(
  '/graphql',
  mammothGraphql<ServerContext>({
    schema,
    graphiql: true,
    context: ({ req }) => ({
      user: req.user || null,
    }),
  }),
);

export default app;
```

Create a `./src/index.ts` file and

```ts
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(s: "world!") }`!