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
166 changes: 85 additions & 81 deletions api/generated-schema.graphql

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/src/graphql/schema/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export const getLocalServer = (getState = store.getState): Array<Server> => {

return [
{
id: 'local',
owner: {
id: 'local',
username: config.remote.username ?? 'root',
url: '',
avatar: '',
Expand Down
2 changes: 2 additions & 0 deletions api/src/unraid-api/auth/api-key.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,13 @@ describe('ApiKeyService', () => {
expect(result).toHaveLength(2);
expect(result[0]).toEqual({
...mockApiKey,
createdAt: expect.any(String),
id: 'test-api-id',
key: 'test-api-key',
});
expect(result[1]).toEqual({
...mockApiKey,
createdAt: expect.any(String),
id: 'unique-id',
key: 'unique-key',
});
Expand Down
8 changes: 4 additions & 4 deletions api/src/unraid-api/graph/graph.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { NoUnusedVariablesRule } from 'graphql';
import { JSONResolver, URLResolver } from 'graphql-scalars';

import { ENVIRONMENT } from '@app/environment.js';
import { GraphQLLong } from '@app/graphql/resolvers/graphql-type-long.js';
import { getters } from '@app/store/index.js';
import {
UsePermissionsDirective,
usePermissionsSchemaTransformer,
} from '@app/unraid-api/graph/directives/use-permissions.directive.js';
import { idPrefixPlugin } from '@app/unraid-api/graph/id-prefix-plugin.js';
import { ResolversModule } from '@app/unraid-api/graph/resolvers/resolvers.module.js';
import { sandboxPlugin } from '@app/unraid-api/graph/sandbox-plugin.js';
import { GraphQLLong } from '@app/unraid-api/graph/scalars/graphql-type-long.js';
import { PrefixedID as PrefixedIDScalar } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';
import { PluginModule } from '@app/unraid-api/plugin/plugin.module.js';

@Module({
Expand All @@ -42,7 +42,7 @@ import { PluginModule } from '@app/unraid-api/plugin/plugin.module.js';
extra,
};
},
plugins: [sandboxPlugin, idPrefixPlugin] as any[],
plugins: [sandboxPlugin] as any[],
subscriptions: {
'graphql-ws': {
path: '/graphql',
Expand All @@ -63,7 +63,7 @@ import { PluginModule } from '@app/unraid-api/plugin/plugin.module.js';
},
}),
],
providers: [],
providers: [PrefixedIDScalar],
exports: [GraphQLModule],
})
export class GraphModule {}
67 changes: 0 additions & 67 deletions api/src/unraid-api/graph/id-prefix-plugin.ts

This file was deleted.

20 changes: 7 additions & 13 deletions api/src/unraid-api/graph/resolvers/api-key/api-key.model.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Field, ID, InputType, ObjectType } from '@nestjs/graphql';
import { Field, InputType, ObjectType } from '@nestjs/graphql';

import { Transform, Type } from 'class-transformer';
import {
ArrayMinSize,
IsArray,
IsBoolean,
IsDate,
IsEnum,
IsNotEmpty,
IsOptional,
IsString,
ValidateIf,
ValidateNested,
} from 'class-validator';

import { Resource, Role } from '@app/unraid-api/graph/resolvers/base.model.js';
import { Node, Resource, Role } from '@app/unraid-api/graph/resolvers/base.model.js';
import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';

@ObjectType()
export class Permission {
Expand All @@ -29,13 +28,8 @@ export class Permission {
actions!: string[];
}

@ObjectType()
export class ApiKey {
@Field(() => ID)
@IsString()
@IsNotEmpty()
id!: string;

@ObjectType({ implements: () => Node })
export class ApiKey extends Node {
@Field()
@IsString()
@IsNotEmpty()
Expand Down Expand Up @@ -119,7 +113,7 @@ export class CreateApiKeyInput {

@InputType()
export class AddRoleForApiKeyInput {
@Field(() => ID)
@Field(() => PrefixedID)
@IsString()
apiKeyId!: string;

Expand All @@ -130,7 +124,7 @@ export class AddRoleForApiKeyInput {

@InputType()
export class RemoveRoleFromApiKeyInput {
@Field(() => ID)
@Field(() => PrefixedID)
@IsString()
apiKeyId!: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@app/unraid-api/graph/resolvers/api-key/api-key.model.js';
import { Resource, Role } from '@app/unraid-api/graph/resolvers/base.model.js';
import { validateObject } from '@app/unraid-api/graph/resolvers/validation.utils.js';
import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';

@Resolver(() => ApiKey)
export class ApiKeyResolver {
Expand All @@ -40,7 +41,10 @@ export class ApiKeyResolver {
resource: Resource.API_KEY,
possession: AuthPossession.ANY,
})
async apiKey(@Args('id') id: string): Promise<ApiKey | null> {
async apiKey(
@Args('id', { type: () => PrefixedID })
id: string
): Promise<ApiKey | null> {
return this.apiKeyService.findById(id);
}

Expand Down
22 changes: 7 additions & 15 deletions api/src/unraid-api/graph/resolvers/array/array.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Field, ID, InputType, Int, ObjectType, registerEnumType } from '@nestjs/graphql';
import { Field, InputType, Int, ObjectType, registerEnumType } from '@nestjs/graphql';

import { IsEnum } from 'class-validator';

import { GraphQLLong } from '@app/graphql/resolvers/graphql-type-long.js';
import { Node } from '@app/unraid-api/graph/resolvers/base.model.js';
import { GraphQLLong } from '@app/unraid-api/graph/scalars/graphql-type-long.js';
import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';

@ObjectType()
export class Capacity {
Expand All @@ -29,10 +30,7 @@ export class ArrayCapacity {
@ObjectType({
implements: () => Node,
})
export class ArrayDisk implements Node {
@Field(() => ID, { description: 'Disk identifier, only set for present disks on the system' })
id!: string;

export class ArrayDisk extends Node {
@Field(() => Int, {
description:
'Array slot number. Parity1 is always 0 and Parity2 is always 29. Array slots will be 1 - 28. Cache slots are 30 - 53. Flash is 54.',
Expand Down Expand Up @@ -132,10 +130,7 @@ export class ArrayDisk implements Node {
@ObjectType({
implements: () => Node,
})
export class UnraidArray implements Node {
@Field(() => ID)
id!: string;

export class UnraidArray extends Node {
@Field(() => ArrayState, { description: 'Current array state' })
state!: ArrayState;

Expand All @@ -157,7 +152,7 @@ export class UnraidArray implements Node {

@InputType()
export class ArrayDiskInput {
@Field(() => ID, { description: 'Disk ID' })
@Field(() => PrefixedID, { description: 'Disk ID' })
id!: string;

@Field(() => Int, { nullable: true, description: 'The slot for the disk' })
Expand Down Expand Up @@ -244,10 +239,7 @@ registerEnumType(ArrayDiskFsColor, {
@ObjectType({
implements: () => Node,
})
export class Share implements Node {
@Field(() => ID)
id!: string;

export class Share extends Node {
@Field(() => String, { description: 'Display name', nullable: true })
name?: string | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { ArrayService } from '@app/unraid-api/graph/resolvers/array/array.service.js';
import { Resource } from '@app/unraid-api/graph/resolvers/base.model.js';
import { ArrayMutations } from '@app/unraid-api/graph/resolvers/mutation/mutation.model.js';
import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';

/**
* Nested Resolvers for Mutations MUST use @ResolveField() instead of @Mutation()
Expand Down Expand Up @@ -62,7 +63,7 @@ export class ArrayMutationsResolver {
resource: Resource.ARRAY,
possession: AuthPossession.ANY,
})
public async mountArrayDisk(@Args('id') id: string): Promise<ArrayDisk> {
public async mountArrayDisk(@Args('id', { type: () => PrefixedID }) id: string): Promise<ArrayDisk> {
const array = await this.arrayService.mountArrayDisk(id);
const disk =
array.disks.find((disk) => disk.id === id) ||
Expand All @@ -82,7 +83,9 @@ export class ArrayMutationsResolver {
resource: Resource.ARRAY,
possession: AuthPossession.ANY,
})
public async unmountArrayDisk(@Args('id') id: string): Promise<ArrayDisk> {
public async unmountArrayDisk(
@Args('id', { type: () => PrefixedID }) id: string
): Promise<ArrayDisk> {
const array = await this.arrayService.unmountArrayDisk(id);
const disk =
array.disks.find((disk) => disk.id === id) ||
Expand All @@ -102,7 +105,9 @@ export class ArrayMutationsResolver {
resource: Resource.ARRAY,
possession: AuthPossession.ANY,
})
public async clearArrayDiskStatistics(@Args('id') id: string): Promise<boolean> {
public async clearArrayDiskStatistics(
@Args('id', { type: () => PrefixedID }) id: string
): Promise<boolean> {
await this.arrayService.clearArrayDiskStatistics(id);
return true;
}
Expand Down
10 changes: 8 additions & 2 deletions api/src/unraid-api/graph/resolvers/base.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Field, ID, InterfaceType, registerEnumType } from '@nestjs/graphql';
import { Field, InterfaceType, registerEnumType } from '@nestjs/graphql';

import { IsNotEmpty, IsString } from 'class-validator';

import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';

// Register enums
export enum Resource {
Expand Down Expand Up @@ -40,7 +44,9 @@ export enum Role {

@InterfaceType()
export class Node {
@Field(() => ID)
@Field(() => PrefixedID)
@IsString()
@IsNotEmpty()
id!: string;
}

Expand Down
7 changes: 2 additions & 5 deletions api/src/unraid-api/graph/resolvers/config/config.model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Field, ID, ObjectType } from '@nestjs/graphql';
import { Field, ObjectType } from '@nestjs/graphql';

import { Node } from '@app/unraid-api/graph/resolvers/base.model.js';

@ObjectType({
implements: () => Node,
})
export class Config implements Node {
@Field(() => ID)
id!: string;

export class Config extends Node {
@Field(() => Boolean, { nullable: true })
valid?: boolean | null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from '@nestjs/common';
import { Args, ID, Mutation, Query, ResolveField, Resolver } from '@nestjs/graphql';
import { Args, Mutation, Query, ResolveField, Resolver } from '@nestjs/graphql';

import { Layout } from '@jsonforms/core';
import { GraphQLJSON, GraphQLJSONObject } from 'graphql-scalars';
Expand All @@ -24,14 +24,15 @@ import {
RemoteAccess,
SetupRemoteAccessInput,
} from '@app/unraid-api/graph/resolvers/connect/connect.model.js';
import { PrefixedID } from '@app/unraid-api/graph/scalars/graphql-type-prefixed-id.js';
import { DataSlice } from '@app/unraid-api/types/json-forms.js';

@Resolver(() => ConnectSettings)
export class ConnectSettingsResolver {
private readonly logger = new Logger(ConnectSettingsResolver.name);
constructor(private readonly connectSettingsService: ConnectSettingsService) {}

@ResolveField(() => ID)
@ResolveField(() => PrefixedID)
public async id(): Promise<string> {
return 'connectSettingsForm';
}
Expand Down
Loading
Loading