Skip to content
Merged
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
4 changes: 4 additions & 0 deletions graphweaver.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"name": "➡️ Example: REST API, MySQL Database and Auth",
"path": "src/examples/rest-with-auth"
},
{
"name": "➡️ Example: SQL Server Database",
"path": "src/examples/sql-server"
},
{
"name": "➡️ Example: SQLite Database",
"path": "src/examples/sqlite"
Expand Down
9 changes: 9 additions & 0 deletions src/examples/s3-storage/src/frontend/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ export type AdminUiFieldExtensionsMetadata = {
key?: Maybe<Scalars['String']['output']>;
};

export type AdminUiFieldFormatMetadata = {
__typename?: 'AdminUiFieldFormatMetadata';
format?: Maybe<Scalars['String']['output']>;
timezone?: Maybe<Scalars['String']['output']>;
type: Scalars['String']['output'];
variant?: Maybe<Scalars['String']['output']>;
};

export type AdminUiFieldMetadata = {
__typename?: 'AdminUiFieldMetadata';
attributes?: Maybe<AdminUiFieldAttributeMetadata>;
detailPanelInputComponent?: Maybe<DetailPanelInputComponent>;
extensions?: Maybe<AdminUiFieldExtensionsMetadata>;
filter?: Maybe<AdminUiFilterMetadata>;
format?: Maybe<AdminUiFieldFormatMetadata>;
hideInDetailForm?: Maybe<Scalars['Boolean']['output']>;
hideInFilterBar?: Maybe<Scalars['Boolean']['output']>;
hideInTable?: Maybe<Scalars['Boolean']['output']>;
Expand Down
9 changes: 9 additions & 0 deletions src/examples/s3-storage/src/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ export type AdminUiFieldExtensionsMetadata = {
key?: Maybe<Scalars['String']['output']>;
};

export type AdminUiFieldFormatMetadata = {
__typename?: 'AdminUiFieldFormatMetadata';
format?: Maybe<Scalars['String']['output']>;
timezone?: Maybe<Scalars['String']['output']>;
type: Scalars['String']['output'];
variant?: Maybe<Scalars['String']['output']>;
};

export type AdminUiFieldMetadata = {
__typename?: 'AdminUiFieldMetadata';
attributes?: Maybe<AdminUiFieldAttributeMetadata>;
detailPanelInputComponent?: Maybe<DetailPanelInputComponent>;
extensions?: Maybe<AdminUiFieldExtensionsMetadata>;
filter?: Maybe<AdminUiFilterMetadata>;
format?: Maybe<AdminUiFieldFormatMetadata>;
hideInDetailForm?: Maybe<Scalars['Boolean']['output']>;
hideInFilterBar?: Maybe<Scalars['Boolean']['output']>;
hideInTable?: Maybe<Scalars['Boolean']['output']>;
Expand Down
11 changes: 11 additions & 0 deletions src/examples/sql-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Dependency directories
node_modules

# dotenv environment variables file
.env
.env.test

# Built artefacts
lib
.graphweaver
18 changes: 18 additions & 0 deletions src/examples/sql-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SQLite Example Graphweaver Project

This project was created by introspecting the [Chinook database](https://github.com/lerocha/chinook-database).

## Running Locally

To run SQL Server in a docker on a mac, you can do the following:

```bash
$ docker pull mcr.microsoft.com/mssql/server:2022-latest
$ docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=[choose_a_password_here]" -p 1433:1433 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2022-latest
```

Then pass the password you chose to Graphweaver as follows:

```bash
$ DATABASE_PASSWORD=[choose_a_password_here] pnpm start
```
28 changes: 28 additions & 0 deletions src/examples/sql-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "sql-server",
"version": "0.1.0",
"description": "sql-server Graphweaver Project",
"scripts": {
"build": "graphweaver build",
"start": "graphweaver start",
"watch": "graphweaver watch",
"import": "graphweaver import"
},
"dependencies": {
"@as-integrations/aws-lambda": "3.1.0",
"@exogee/graphweaver": "workspace:*",
"@exogee/graphweaver-scalars": "workspace:*",
"@exogee/graphweaver-server": "workspace:*",
"@exogee/graphweaver-mikroorm": "workspace:*",
"@mikro-orm/core": "6.4.14",
"@mikro-orm/knex": "6.4.14",
"@mikro-orm/mssql": "6.4.14",
"tedious": "18.6.1",
"graphql": "16.10.0"
},
"devDependencies": {
"@types/node": "22.13.14",
"graphweaver": "2.16.1",
"typescript": "5.8.3"
}
}
17 changes: 17 additions & 0 deletions src/examples/sql-server/src/backend/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MsSqlDriver } from '@mikro-orm/mssql';
import { entities } from './entities';

export const connection = {
connectionManagerId: 'mssql',
mikroOrmConfig: {
entities,
driver: MsSqlDriver,
dbName: process.env.DATABASE_NAME || 'Chinook',
host: process.env.DATABASE_HOST || '127.0.0.1',
user: process.env.DATABASE_USER || 'sa',
password: process.env.DATABASE_PASSWORD,
port: process.env.DATABASE_PORT ? parseInt(process.env.DATABASE_PORT) : 1433,
},
};

export const connections = [connection];
1 change: 1 addition & 0 deletions src/examples/sql-server/src/backend/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './mssql';
18 changes: 18 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import { Artist } from './artist';
import { Track } from './track';

@Entity({ tableName: 'Album' })
export class Album {
@PrimaryKey({ fieldName: 'AlbumId', type: 'integer' })
albumId!: number;

@Property({ fieldName: 'Title', type: 'string', length: 160 })
title!: string;

@ManyToOne({ entity: () => Artist, ref: true, fieldName: 'ArtistId', index: 'IFK_AlbumArtistId' })
artist!: Ref<Artist>;

@OneToMany({ entity: () => Track, mappedBy: 'album' })
tracks = new Collection<Track>(this);
}
14 changes: 14 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/artist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { Album } from './album';

@Entity({ tableName: 'Artist' })
export class Artist {
@PrimaryKey({ fieldName: 'ArtistId', type: 'integer' })
artistId!: number;

@Property({ fieldName: 'Name', type: 'string', length: 120, nullable: true })
name?: string;

@OneToMany({ entity: () => Album, mappedBy: 'artist' })
albums = new Collection<Album>(this);
}
48 changes: 48 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import { Employee } from './employee';
import { Invoice } from './invoice';

@Entity({ tableName: 'Customer' })
export class Customer {
@PrimaryKey({ fieldName: 'CustomerId', type: 'integer' })
customerId!: number;

@Property({ fieldName: 'FirstName', type: 'string', length: 40 })
firstName!: string;

@Property({ fieldName: 'LastName', type: 'string', length: 20 })
lastName!: string;

@Property({ fieldName: 'Company', type: 'string', length: 80, nullable: true })
company?: string;

@Property({ fieldName: 'Address', type: 'string', length: 70, nullable: true })
address?: string;

@Property({ fieldName: 'City', type: 'string', length: 40, nullable: true })
city?: string;

@Property({ fieldName: 'State', type: 'string', length: 40, nullable: true })
state?: string;

@Property({ fieldName: 'Country', type: 'string', length: 40, nullable: true })
country?: string;

@Property({ fieldName: 'PostalCode', type: 'string', length: 10, nullable: true })
postalCode?: string;

@Property({ fieldName: 'Phone', type: 'string', length: 24, nullable: true })
phone?: string;

@Property({ fieldName: 'Fax', type: 'string', length: 24, nullable: true })
fax?: string;

@Property({ fieldName: 'Email', type: 'string', length: 60 })
email!: string;

@ManyToOne({ entity: () => Employee, ref: true, fieldName: 'SupportRepId', nullable: true, index: 'IFK_CustomerSupportRepId' })
employee?: Ref<Employee>;

@OneToMany({ entity: () => Invoice, mappedBy: 'customer' })
invoices = new Collection<Invoice>(this);
}
56 changes: 56 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/employee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import { Customer } from './customer';

@Entity({ tableName: 'Employee' })
export class Employee {
@PrimaryKey({ fieldName: 'EmployeeId', type: 'integer' })
employeeId!: number;

@Property({ fieldName: 'LastName', type: 'string', length: 20 })
lastName!: string;

@Property({ fieldName: 'FirstName', type: 'string', length: 20 })
firstName!: string;

@Property({ fieldName: 'Title', type: 'string', length: 30, nullable: true })
title?: string;

@ManyToOne({ entity: () => Employee, ref: true, fieldName: 'ReportsTo', nullable: true, index: 'IFK_EmployeeReportsTo' })
employee?: Ref<Employee>;

@Property({ fieldName: 'BirthDate', type: 'datetime', length: 3, nullable: true })
birthDate?: Date;

@Property({ fieldName: 'HireDate', type: 'datetime', length: 3, nullable: true })
hireDate?: Date;

@Property({ fieldName: 'Address', type: 'string', length: 70, nullable: true })
address?: string;

@Property({ fieldName: 'City', type: 'string', length: 40, nullable: true })
city?: string;

@Property({ fieldName: 'State', type: 'string', length: 40, nullable: true })
state?: string;

@Property({ fieldName: 'Country', type: 'string', length: 40, nullable: true })
country?: string;

@Property({ fieldName: 'PostalCode', type: 'string', length: 10, nullable: true })
postalCode?: string;

@Property({ fieldName: 'Phone', type: 'string', length: 24, nullable: true })
phone?: string;

@Property({ fieldName: 'Fax', type: 'string', length: 24, nullable: true })
fax?: string;

@Property({ fieldName: 'Email', type: 'string', length: 60, nullable: true })
email?: string;

@OneToMany({ entity: () => Customer, mappedBy: 'employee' })
customers = new Collection<Customer>(this);

@OneToMany({ entity: () => Employee, mappedBy: 'employee' })
employees = new Collection<Employee>(this);
}
14 changes: 14 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/genre.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { Track } from './track';

@Entity({ tableName: 'Genre' })
export class Genre {
@PrimaryKey({ fieldName: 'GenreId', type: 'integer' })
genreId!: number;

@Property({ fieldName: 'Name', type: 'string', length: 120, nullable: true })
name?: string;

@OneToMany({ entity: () => Track, mappedBy: 'genre' })
tracks = new Collection<Track>(this);
}
34 changes: 34 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Album } from './album';
import { Artist } from './artist';
import { Customer } from './customer';
import { Employee } from './employee';
import { Genre } from './genre';
import { Invoice } from './invoice';
import { InvoiceLine } from './invoice-line';
import { MediaType } from './media-type';
import { Playlist } from './playlist';
import { Track } from './track';

export * from './album';
export * from './artist';
export * from './customer';
export * from './employee';
export * from './genre';
export * from './invoice';
export * from './invoice-line';
export * from './media-type';
export * from './playlist';
export * from './track';

export const entities = [
Album,
Artist,
Customer,
Employee,
Genre,
Invoice,
InvoiceLine,
MediaType,
Playlist,
Track,
];
21 changes: 21 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/invoice-line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Entity, ManyToOne, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import { Invoice } from './invoice';
import { Track } from './track';

@Entity({ tableName: 'InvoiceLine' })
export class InvoiceLine {
@PrimaryKey({ fieldName: 'InvoiceLineId', type: 'integer' })
invoiceLineId!: number;

@ManyToOne({ entity: () => Invoice, ref: true, fieldName: 'InvoiceId', index: 'IFK_InvoiceLineInvoiceId' })
invoice!: Ref<Invoice>;

@ManyToOne({ entity: () => Track, ref: true, fieldName: 'TrackId', index: 'IFK_InvoiceLineTrackId' })
track!: Ref<Track>;

@Property({ fieldName: 'UnitPrice', type: 'decimal' })
unitPrice!: string;

@Property({ fieldName: 'Quantity', type: 'integer' })
quantity!: number;
}
36 changes: 36 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/invoice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import { Customer } from './customer';
import { InvoiceLine } from './invoice-line';

@Entity({ tableName: 'Invoice' })
export class Invoice {
@PrimaryKey({ fieldName: 'InvoiceId', type: 'integer' })
invoiceId!: number;

@ManyToOne({ entity: () => Customer, ref: true, fieldName: 'CustomerId', index: 'IFK_InvoiceCustomerId' })
customer!: Ref<Customer>;

@Property({ fieldName: 'InvoiceDate', type: 'datetime', length: 3 })
invoiceDate!: Date;

@Property({ fieldName: 'BillingAddress', type: 'string', length: 70, nullable: true })
billingAddress?: string;

@Property({ fieldName: 'BillingCity', type: 'string', length: 40, nullable: true })
billingCity?: string;

@Property({ fieldName: 'BillingState', type: 'string', length: 40, nullable: true })
billingState?: string;

@Property({ fieldName: 'BillingCountry', type: 'string', length: 40, nullable: true })
billingCountry?: string;

@Property({ fieldName: 'BillingPostalCode', type: 'string', length: 10, nullable: true })
billingPostalCode?: string;

@Property({ fieldName: 'Total', type: 'decimal' })
total!: string;

@OneToMany({ entity: () => InvoiceLine, mappedBy: 'invoice' })
invoiceLines = new Collection<InvoiceLine>(this);
}
14 changes: 14 additions & 0 deletions src/examples/sql-server/src/backend/entities/mssql/media-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { Track } from './track';

@Entity({ tableName: 'MediaType' })
export class MediaType {
@PrimaryKey({ fieldName: 'MediaTypeId', type: 'integer' })
mediaTypeId!: number;

@Property({ fieldName: 'Name', type: 'string', length: 120, nullable: true })
name?: string;

@OneToMany({ entity: () => Track, mappedBy: 'mediaType' })
tracks = new Collection<Track>(this);
}
Loading
Loading