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

@nestjs/apollo

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/apollo

Nest - modern, fast, powerful node.js web framework (@apollo)

  • 11.0.0-next.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
334K
decreased by-18.86%
Maintainers
2
Weekly downloads
 
Created

What is @nestjs/apollo?

@nestjs/apollo is a package that integrates Apollo Server with the NestJS framework, allowing developers to build GraphQL APIs with ease. It provides decorators and utilities to create GraphQL schemas, resolvers, and more, leveraging the power of both Apollo Server and NestJS.

What are @nestjs/apollo's main functionalities?

GraphQL Module Setup

This feature allows you to set up the GraphQL module with Apollo Server as the driver. The `autoSchemaFile` option automatically generates the GraphQL schema file.

const { Module } = require('@nestjs/common');
const { GraphQLModule } = require('@nestjs/graphql');
const { ApolloDriver, ApolloDriverConfig } = require('@nestjs/apollo');

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      autoSchemaFile: true,
    }),
  ],
})
class AppModule {}

Creating Resolvers

This feature allows you to create GraphQL resolvers using decorators. The `@Resolver` decorator marks the class as a resolver, and the `@Query` decorator defines a query field.

const { Resolver, Query } = require('@nestjs/graphql');

@Resolver()
class SampleResolver {
  @Query(() => String)
  sayHello() {
    return 'Hello World!';
  }
}

Using GraphQL Scalars

This feature allows you to define custom GraphQL scalars. The `@Scalar` decorator is used to create a new scalar type, and methods like `parseValue`, `serialize`, and `parseLiteral` handle the conversion between client and server.

const { Scalar } = require('@nestjs/graphql');
const { Kind } = require('graphql');

@Scalar('Date')
class DateScalar {
  parseValue(value) {
    return new Date(value); // value from the client input variables
  }
  serialize(value) {
    return value.getTime(); // value sent to the client
  }
  parseLiteral(ast) {
    if (ast.kind === Kind.INT) {
      return new Date(parseInt(ast.value, 10)); // ast value is always in string format
    }
    return null;
  }
}

Other packages similar to @nestjs/apollo

FAQs

Package last updated on 01 Mar 2023

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