Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .editorConfig → .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

indent_style = space
indent_size = 2
max_line_length = 80
indent_style = tab
indent_size = 4
max_line_length = 120
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup pnpm
uses: pnpm/action-setup@ff378ebe6b225b0680b81c1ad4498ae0d1d3a5e3 # v6.0.10

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm run build

- name: Lint
run: pnpm run lint

- name: Check formatting
run: pnpm run format:check

- name: Test
run: pnpm run test
16 changes: 0 additions & 16 deletions .github/workflows/main.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup pnpm
uses: pnpm/action-setup@ff378ebe6b225b0680b81c1ad4498ae0d1d3a5e3 # v6.0.10

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: pnpm
registry-url: https://registry.npmjs.org

# Install without running dependency lifecycle scripts, so a
# compromised/malicious transitive dependency can't read NPM_TOKEN
# off this job's environment. Native builds we actually need
# (sqlite3, @apollo/protobufjs) are approved in pnpm-workspace.yaml
# and only needed for tests, which don't run in this job.
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts

- name: Build
run: pnpm run build

- name: Verify package version matches tag
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
if [ "$PKG_VERSION" != "$GITHUB_REF_NAME" ]; then
echo "package.json version ($PKG_VERSION) does not match tag ($GITHUB_REF_NAME)"
exit 1
fi

- name: Publish to npm
run: pnpm publish --no-git-checks --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
yarn-error.log
node_modules/
coverage/
.husky/_

dist/examples/
dist/tests/

dist/**/*.map

#dist/
dist/
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.0
24
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
coverage/
pnpm-lock.yaml
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"useTabs": true,
"tabWidth": 4,
"printWidth": 120
}
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 16.14.0
nodejs 24.19.0
69 changes: 37 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,43 @@ TypeGraphQL-DataLoader is an utility to use DataLoader with TypeGraphQL without

## Why does this fork exist?

The original library seems to be abandon-ware these days, but it is a very useful glue between `type-graphql`, `typeorm`, and `@apollo/server`. However, the version of the original library doesn't support modern versions of apollo/graphql/etc. So this fork modernizes all dependencies.
The original library seems to be abandon-ware these days, but it is a very useful glue between `type-graphql`, `typeorm`, and `@apollo/server`. However, the version of the original library doesn't support modern versions of apollo/graphql/etc. So this fork modernizes all dependencies.

### Breaking changes

* Switched to ESM
* Compatible with graphql 16
* Compatible with apollo 5
* Compatible with express 4 or 5
* Compatible with type-graphql 2.x
- Switched to ESM
- Compatible with graphql 16
- Compatible with apollo 5
- Compatible with express 4 or 5
- Compatible with type-graphql 2.x

## Install

Because the upstream package is now abandon-ware, the package can be pulled directly from github using the following npm command:
Because the upstream package is now abandon-ware, this fork is published under its own npm scope:

```
npm install github:@isoft-data-systems/type-graphql-dataloader
npm install @isoftdata/type-graphql-dataloader
```

This will create an installation from github instead of from the node package manager.
To pin an exact commit instead (e.g. before it's published, or to test an unreleased fix),
install directly from a tag on GitHub:

```
npm install github:ISoft-Data-Systems/type-graphql-dataloader#v0.6.3
```

The latest build is tested with the following packages:

* type-graphql 2
* @apollo/server 5
* (optional) typeorm 0.3
- type-graphql 2
- @apollo/server 5
- (optional) typeorm 0.3

## Getting Started

Apollo Server is the first-class supported server. If your application uses Apollo Server, pass `ApolloServerLoaderPlugin()` as a plugin when instantiating the server. This plugin is for set-up and clean-up against each request.

```ts
import { ApolloServerLoaderPlugin } from "type-graphql-dataloader";
import { ApolloServerLoaderPlugin } from "@isoftdata/type-graphql-dataloader";
import { DataSource } from "typeorm";

// Instantiate modern typeorm datasource, connect it to the database
Expand All @@ -59,41 +64,41 @@ TypeORM is the first-class supported ORM. If your application uses TypeORM with

```ts
import { ObjectType, Field, ID } from "type-graphql";
import { TypeormLoader } from "type-graphql-dataloader";
import { TypeormLoader } from "@isoftdata/type-graphql-dataloader";
import { Entity, PrimaryGeneratedColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";

@ObjectType()
@Entity()
export class Photo {
@Field((type) => ID)
@PrimaryGeneratedColumn()
id: number;

@Field((type) => User)
@ManyToOne((type) => User, (user) => user.photos)
@TypeormLoader()
user: User;
@Field((type) => ID)
@PrimaryGeneratedColumn()
id: number;

@Field((type) => User)
@ManyToOne((type) => User, (user) => user.photos)
@TypeormLoader()
user: User;
}
```

```ts
import { ObjectType, Field, ID } from "type-graphql";
import { TypeormLoader } from "type-graphql-dataloader";
import { TypeormLoader } from "@isoftdata/type-graphql-dataloader";
import { Entity, PrimaryGeneratedColumn, OneToMany, RelationId } from "typeorm";
import { Photo } from "./Photo";

@ObjectType()
@Entity()
export class User {
@Field((type) => ID)
@PrimaryGeneratedColumn()
id: number;

@Field((type) => [Photo])
@OneToMany((type) => Photo, (photo) => photo.user)
@TypeormLoader()
photos: Photo[];
@Field((type) => ID)
@PrimaryGeneratedColumn()
id: number;

@Field((type) => [Photo])
@OneToMany((type) => Photo, (photo) => photo.user)
@TypeormLoader()
photos: Photo[];
}
```

Expand All @@ -107,7 +112,7 @@ It is possible to assign custom DataLoader to a field by adding `@Loader` decora
import DataLoader from "dataloader";
import { groupBy } from "lodash";
import { Resolver, Query, FieldResolver, Root } from "type-graphql";
import { Loader } from "type-graphql-dataloader";
import { Loader } from "@isoftdata/type-graphql-dataloader";
import { getRepository, In } from "typeorm";
import { Photo } from "./Photo";
import { User } from "./User";
Expand Down
8 changes: 0 additions & 8 deletions dist/decorators/Loader.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions dist/decorators/Loader.js

This file was deleted.

5 changes: 0 additions & 5 deletions dist/decorators/typeorm/ExplicitLoaderImpl.d.ts

This file was deleted.

Loading