refactor source code
This commit is contained in:
@@ -1,82 +1,82 @@
|
||||
import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars';
|
||||
import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars'
|
||||
import PrismaPlugin, {
|
||||
PothosPrismaDatamodel,
|
||||
PrismaClient,
|
||||
} from '@pothos/plugin-prisma';
|
||||
import { Request, Response } from 'express';
|
||||
} from '@pothos/plugin-prisma'
|
||||
import { Request, Response } from 'express'
|
||||
import SmartSubscriptionPlugin, {
|
||||
subscribeOptionsFromIterator,
|
||||
} from '@pothos/plugin-smart-subscriptions';
|
||||
} from '@pothos/plugin-smart-subscriptions'
|
||||
|
||||
import AuthzPlugin from '@pothos/plugin-authz';
|
||||
import ErrorsPlugin from '@pothos/plugin-errors';
|
||||
import type { FileUpload } from 'graphql-upload/processRequest.js';
|
||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaCrudGenerator } from './graphql.generator';
|
||||
import type PrismaTypes from '../types/pothos.generated';
|
||||
import PrismaUtils from '@pothos/plugin-prisma-utils';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
import RelayPlugin from '@pothos/plugin-relay';
|
||||
import SchemaBuilder from '@pothos/core';
|
||||
import SimpleObjectPlugin from '@pothos/plugin-simple-objects';
|
||||
import { User } from '@prisma/client';
|
||||
import { getDatamodel } from '../types/pothos.generated';
|
||||
import AuthzPlugin from '@pothos/plugin-authz'
|
||||
import ErrorsPlugin from '@pothos/plugin-errors'
|
||||
import type { FileUpload } from 'graphql-upload/processRequest.js'
|
||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { PrismaCrudGenerator } from './graphql.generator'
|
||||
import type PrismaTypes from '../types/pothos.generated'
|
||||
import PrismaUtils from '@pothos/plugin-prisma-utils'
|
||||
import { PubSub } from 'graphql-subscriptions'
|
||||
import RelayPlugin from '@pothos/plugin-relay'
|
||||
import SchemaBuilder from '@pothos/core'
|
||||
import SimpleObjectPlugin from '@pothos/plugin-simple-objects'
|
||||
import { User } from '@prisma/client'
|
||||
import { getDatamodel } from '../types/pothos.generated'
|
||||
|
||||
// import { rules } from '../common/graphql/common.graphql.auth-rule';
|
||||
|
||||
export type SchemaContext =
|
||||
| {
|
||||
isSubscription: true;
|
||||
isSubscription: true
|
||||
websocket: {
|
||||
pubSub: PubSub;
|
||||
me: User;
|
||||
generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
};
|
||||
pubSub: PubSub
|
||||
me: User
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
}
|
||||
}
|
||||
| {
|
||||
isSubscription: false;
|
||||
isSubscription: false
|
||||
http: {
|
||||
req: Request;
|
||||
res: Response;
|
||||
me: User;
|
||||
pubSub: PubSub;
|
||||
generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
};
|
||||
};
|
||||
req: Request
|
||||
res: Response
|
||||
me: User
|
||||
pubSub: PubSub
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
}
|
||||
}
|
||||
|
||||
// extend prisma types to contain string type
|
||||
export interface SchemaBuilderOption {
|
||||
Context: SchemaContext;
|
||||
PrismaTypes: PrismaTypes;
|
||||
DataModel: PothosPrismaDatamodel;
|
||||
Context: SchemaContext
|
||||
PrismaTypes: PrismaTypes
|
||||
DataModel: PothosPrismaDatamodel
|
||||
Connection: {
|
||||
totalCount: number | (() => number | Promise<number>);
|
||||
};
|
||||
totalCount: number | (() => number | Promise<number>)
|
||||
}
|
||||
// AuthZRule: keyof typeof rules;
|
||||
Scalars: {
|
||||
DateTime: {
|
||||
Input: Date;
|
||||
Output: Date;
|
||||
};
|
||||
Input: Date
|
||||
Output: Date
|
||||
}
|
||||
Json: {
|
||||
Input: JSON;
|
||||
Output: JSON;
|
||||
};
|
||||
Input: JSON
|
||||
Output: JSON
|
||||
}
|
||||
Upload: {
|
||||
Input: FileUpload;
|
||||
Output: FileUpload;
|
||||
};
|
||||
Input: FileUpload
|
||||
Output: FileUpload
|
||||
}
|
||||
Int: {
|
||||
Input: number;
|
||||
Output: number | bigint | string;
|
||||
};
|
||||
};
|
||||
Input: number
|
||||
Output: number | bigint | string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
public generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
public generator: PrismaCrudGenerator<BuilderTypes>
|
||||
|
||||
constructor(private readonly prisma: PrismaClient) {
|
||||
super({
|
||||
@@ -93,9 +93,9 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
debounceDelay: 1000,
|
||||
...subscribeOptionsFromIterator((name, ctx) => {
|
||||
if (ctx.isSubscription) {
|
||||
return ctx.websocket.pubSub.asyncIterator(name);
|
||||
return ctx.websocket.pubSub.asyncIterator(name)
|
||||
}
|
||||
return ctx.http.pubSub.asyncIterator(name);
|
||||
return ctx.http.pubSub.asyncIterator(name)
|
||||
}),
|
||||
},
|
||||
relay: {},
|
||||
@@ -109,15 +109,15 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
errors: {
|
||||
defaultTypes: [],
|
||||
},
|
||||
});
|
||||
this.generator = new PrismaCrudGenerator<BuilderTypes>(this);
|
||||
this.addScalarType('DateTime', DateTimeResolver);
|
||||
this.addScalarType('Json', JSONObjectResolver);
|
||||
this.addScalarType('Upload', GraphQLUpload);
|
||||
})
|
||||
this.generator = new PrismaCrudGenerator<BuilderTypes>(this)
|
||||
this.addScalarType('DateTime', DateTimeResolver)
|
||||
this.addScalarType('Json', JSONObjectResolver)
|
||||
this.addScalarType('Upload', GraphQLUpload)
|
||||
|
||||
this.queryType({});
|
||||
this.mutationType({});
|
||||
this.subscriptionType({});
|
||||
this.queryType({})
|
||||
this.mutationType({})
|
||||
this.subscriptionType({})
|
||||
|
||||
this.globalConnectionField('totalCount', (t) =>
|
||||
t.int({
|
||||
@@ -127,10 +127,10 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
? parent.totalCount()
|
||||
: parent.totalCount,
|
||||
}),
|
||||
);
|
||||
)
|
||||
|
||||
// test print ManagedServiceWhereUniqueInput
|
||||
}
|
||||
}
|
||||
export type BuilderTypes =
|
||||
PothosSchemaTypes.ExtendDefaultTypes<SchemaBuilderOption>;
|
||||
PothosSchemaTypes.ExtendDefaultTypes<SchemaBuilderOption>
|
||||
|
||||
Reference in New Issue
Block a user