Skip to content

Instantly share code, notes, and snippets.

View tugascript's full-sized avatar

Afonso Barracha tugascript

View GitHub Profile
@tugascript
tugascript / graphql.config.ts
Created February 8, 2023 22:09
Mercurius Configuration
import { HttpException, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { GqlOptionsFactory } from '@nestjs/graphql';
import { MercuriusDriverConfig, MercuriusPlugin } from '@nestjs/mercurius';
import AltairFastify, {
AltairFastifyPluginOptions,
} from 'altair-fastify-plugin';
import { GraphQLError } from 'graphql';
import Redis, { RedisOptions } from 'ioredis';
import mercuriusCache, { MercuriusCacheOptions } from 'mercurius-cache';
@tugascript
tugascript / build-mercurius-federated-schema.util.ts
Created April 15, 2022 09:39
Mercurius drivers with plugins
import { loadPackage } from '@nestjs/common/utils/load-package.util';
import { transformSchema } from '@nestjs/graphql';
import { BuildFederatedSchemaOptions } from '@nestjs/graphql';
import { GraphQLSchema, isObjectType, buildASTSchema } from 'graphql';
import { forEach } from 'lodash';
export function buildMercuriusFederatedSchema({
typeDefs,
resolvers,
}: BuildFederatedSchemaOptions) {
@tugascript
tugascript / chat-messages.resolver.ts
Last active March 29, 2022 07:35
Notification System with Apollo GraphQL and NestJS
/*
* This is just an example
*/
import { Inject, ParseIntPipe, UseGuards } from '@nestjs/common';
import {
Args,
Int,
Mutation,
Resolver,
@tugascript
tugascript / paginated.interface.ts
Last active August 30, 2024 05:11
A Generic Paginated Type for GraphQL in NestJS code first approach
export interface IEdge<T> {
cursor: string;
node: T;
}
interface IPageInfo {
endCursor: string;
hasNextPage: boolean;
}