mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2026-06-04 07:34:26 -06:00
PR-393405:
chore: update dependencies and version to 1.6.0 feat: refactor GraphQL resolvers for improved structure and functionality - Split TestResolver into TestResolverQuery and TestResolverMutation - Implement FieldResolvers for dynamic data fetching fix: update import paths for graphql-ws to use new module structure chore: add ESLint configuration for improved code quality - Migrate from previous ESLint config to a new structure with TypeScript support style: update TypeScript target to ES2021 for better compatibility
This commit is contained in:
4
src/@types/custom.d.ts
vendored
4
src/@types/custom.d.ts
vendored
@@ -7,4 +7,8 @@ declare module "*.gql" {
|
||||
declare module 'cookie-parse' {
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module 'graphql-ws/use/ws' {
|
||||
export * from 'graphql-ws/dist/use/ws';
|
||||
}
|
||||
1
src/GraphQL/resolvers/index.ts
Normal file
1
src/GraphQL/resolvers/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './test.resolver';
|
||||
@@ -1,19 +1,33 @@
|
||||
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||
'use strict';
|
||||
|
||||
import { Query, Resolver, Mutation } from 'type-graphql';
|
||||
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
||||
import { Query, Resolver, Mutation, FieldResolver, Root, Arg } from 'type-graphql';
|
||||
import { Test, TestMutation } from '@GraphQL/schema';
|
||||
import { getTest, addText } from '@controllerGraphQL';
|
||||
|
||||
@Resolver(() => Test)
|
||||
export class TestResolver {
|
||||
export class TestResolverQuery {
|
||||
@Query(() => Test)
|
||||
async test() {
|
||||
return Test;
|
||||
return {};
|
||||
}
|
||||
|
||||
@Mutation(() => TestMutation)
|
||||
async testMutation() {
|
||||
return TestMutation;
|
||||
}
|
||||
@FieldResolver(() => String)
|
||||
async text() {
|
||||
return await getTest({});
|
||||
}
|
||||
}
|
||||
|
||||
@Resolver(() => TestMutation)
|
||||
export class TestResolverMutation {
|
||||
@Mutation(() => TestMutation)
|
||||
async testMutation() {
|
||||
return {};
|
||||
}
|
||||
|
||||
@FieldResolver(() => String)
|
||||
async text(@Arg('text') text?: string){
|
||||
return await addText({text});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
import { buildSchemaSync } from "type-graphql"
|
||||
import { TestResolver } from "@GraphQL/resolvers/test.resolver";
|
||||
import {
|
||||
TestResolverQuery,
|
||||
TestResolverMutation
|
||||
} from "@GraphQL/resolvers";
|
||||
|
||||
export * from './test.schema'
|
||||
|
||||
const schema = buildSchemaSync({
|
||||
resolvers: [TestResolver],
|
||||
resolvers: [
|
||||
TestResolverQuery,
|
||||
TestResolverMutation,
|
||||
],
|
||||
emitSchemaFile: true,
|
||||
})
|
||||
export default schema
|
||||
@@ -1,21 +1,16 @@
|
||||
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||
'use strict';
|
||||
|
||||
import { Field, ObjectType, Arg } from 'type-graphql';
|
||||
import { getTest, addText } from '@controllerGraphQL';
|
||||
import { Field, ObjectType } from 'type-graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Test {
|
||||
@Field(() => String)
|
||||
async text(){
|
||||
return await getTest({});
|
||||
}
|
||||
text?: string;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TestMutation {
|
||||
@Field(() => String)
|
||||
async text(@Arg('text') text?: string){
|
||||
return await addText({text});
|
||||
}
|
||||
text?: string;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import ws from 'ws'; // yarn add ws
|
||||
import express from 'express'; //express
|
||||
import cors from 'cors';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import { useServer } from 'graphql-ws/lib/use/ws';
|
||||
import { useServer } from 'graphql-ws/use/ws';
|
||||
import { execute, subscribe } from 'graphql';
|
||||
import GraphQLserver from '@GraphQL/server';// Server of GraphQL,
|
||||
import expressPlayground from 'graphql-playground-middleware-express';
|
||||
|
||||
Reference in New Issue
Block a user