New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

@galaxy-stack/orbit-graphql

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@galaxy-stack/orbit-graphql

GraphQL module for Orbit framework

latest
Source
npmnpm
Version
0.1.15
Version published
Maintainers
1
Created
Source

@galaxy-stack/orbit-graphql

npm version docs

Part of the Orbit framework — a NestJS-style backend framework for Bun.

Installation

bun add @galaxy-stack/orbit-graphql

@galaxy-stack/orbit-graphql

Mô tả

Module GraphQL cho Orbit với code-first approach, DataLoader support và WebSocket subscriptions.

Tính năng chính

1. Code-First Decorators

import { 
  ObjectType, Field, Query, Mutation, 
  Resolver, Args, Int 
} from '@galaxy-stack/orbit-graphql';

@ObjectType()
class User {
  @Field(() => Int)
  id!: number;

  @Field()
  name!: string;

  @Field({ nullable: true })
  email?: string;
}

@Resolver(() => User)
class UserResolver {
  @Query(() => User)
  async user(@Args('id', Int) id: number) {
    return await this.userService.findById(id);
  }

  @Query(() => [User])
  async users() {
    return await this.userService.findAll();
  }

  @Mutation(() => User)
  async createUser(@Args('input') input: CreateUserInput) {
    return await this.userService.create(input);
  }
}

2. Input Types

@InputType()
class CreateUserInput {
  @Field()
  name!: string;

  @Field({ nullable: true })
  email?: string;
}

3. DataLoader (N+1 Prevention)

import { createDataLoader, ResolveField, Parent } from '@galaxy-stack/orbit-graphql';

@Resolver(() => Post)
class PostResolver {
  private authorLoader = createDataLoader(
    async (ids: number[]) => this.userService.findByIds(ids)
  );

  @ResolveField(() => User)
  async author(@Parent() post: Post) {
    return this.authorLoader.load(post.authorId);
  }
}

4. Subscriptions

import { Subscription, PubSub } from '@galaxy-stack/orbit-graphql';

@Resolver()
class NotificationResolver {
  @Subscription(() => Notification)
  notificationAdded() {
    return pubSub.asyncIterator('NOTIFICATION_ADDED');
  }
}

// Publish event
pubSub.publish('NOTIFICATION_ADDED', { notificationAdded: notification });

Cấu hình Module

import { GraphQLModule } from '@galaxy-stack/orbit-graphql';

@Module({
  imports: [
    GraphQLModule.forRoot({
      autoSchemaFile: true,
      playground: true,
      subscriptions: {
        'graphql-ws': true,
      },
    }),
  ],
  providers: [UserResolver, PostResolver],
})
class AppModule {}

Field Decorators

@ObjectType()
class Product {
  @Field(() => Int)
  id!: number;

  @Field(() => Float)
  price!: number;

  @Field(() => [String])
  tags!: string[];

  @Field(() => Int, { defaultValue: 0 })
  stock!: number;

  @Field({ deprecationReason: 'Use newField instead' })
  oldField!: string;
}

Enums

import { registerEnumType } from '@galaxy-stack/orbit-graphql';

enum UserRole {
  ADMIN = 'ADMIN',
  USER = 'USER',
}

registerEnumType(UserRole, { name: 'UserRole' });

@ObjectType()
class User {
  @Field(() => UserRole)
  role!: UserRole;
}

Guards & Interceptors

@UseGuards(GqlAuthGuard)
@Resolver()
class ProtectedResolver {
  @Query(() => String)
  @UseInterceptors(LoggingInterceptor)
  protected() {
    return 'Protected data';
  }
}

FAQs

Package last updated on 26 Sep 2026

Related posts