Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@as-integrations/next
Advanced tools
An Apollo Server integration for use with Next.js.
First create a Next.js API route by creating a file at for example pages/api/graphql.js
.
This API route will be accessible at /api/graphql
.
Next, create an Apollo Server instance and pass it to startServerAndCreateNextHandler
:
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { gql } from 'graphql-tag';
const resolvers = {
Query: {
hello: () => 'world',
},
};
const typeDefs = gql`
type Query {
hello: String
}
`;
const server = new ApolloServer({
resolvers,
typeDefs,
});
export default startServerAndCreateNextHandler(server);
You may also pass a context function to startServerAndCreateNextHandler
as such:
export default startServerAndCreateNextHandler(server, {
context: async (req, res) => ({ req, res, user: await getLoggedInUser(req) }),
});
The Next.js req
and res
objects are passed along to the context function.
First create a Next.js Route Handler by creating a file at for example app/api/graphql/route.js
.
This Route Handler will be accessible at /api/graphql
.
Next, create an Apollo Server instance, pass it to startServerAndCreateNextHandler
and
finally export the handler both as GET and POST:
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { ApolloServer } from '@apollo/server';
import { gql } from 'graphql-tag';
const resolvers = {
Query: {
hello: () => 'world',
},
};
const typeDefs = gql`
type Query {
hello: String
}
`;
const server = new ApolloServer({
resolvers,
typeDefs,
});
const handler = startServerAndCreateNextHandler(server);
export { handler as GET, handler as POST };
When using this integration with Route Handlers you will have to specify the type of the incoming request object (Response
or NextResponse
) for the context function to receive the correct type signature:
import { NextRequest } from 'next/server';
// req has the type NextRequest
const handler = startServerAndCreateNextHandler<NextRequest>(server, {
context: async req => ({ req }),
});
FAQs
An Apollo Server integration for use with Next.js
The npm package @as-integrations/next receives a total of 25,103 weekly downloads. As such, @as-integrations/next popularity was classified as popular.
We found that @as-integrations/next 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.