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

@freshsqueezed/apollo-next

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@freshsqueezed/apollo-next

Apollo server integration for nextjs framework

  • 0.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@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 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 built into the nextjs framework:

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 }!

FAQs

Package last updated on 03 Nov 2022

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