mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-07-01 02:08:27 -06:00
PR-757991: adding typegraphql.
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import { getTest, addText } from '@controllerGraphQL';
|
||||
|
||||
// A map of functions which return data for the schema.
|
||||
const resolvers = {
|
||||
Query: {
|
||||
// eslint-disable-next-line
|
||||
test: (rootValue: any, args: any, context: any) => ({}),
|
||||
},
|
||||
Mutation: {
|
||||
// eslint-disable-next-line
|
||||
testMutation: (rootValue: any, args: any, context: any) => ({}),
|
||||
},
|
||||
Test: {
|
||||
test: (rootValue: any, args: any, context: any) => getTest({rootValue, args, context})
|
||||
},
|
||||
TestMutation: {
|
||||
testMutation: (rootValue: any, args: any, context: any) => addText({rootValue, args, context})
|
||||
}
|
||||
};
|
||||
|
||||
export default resolvers;
|
18
src/GraphQL/resolvers/test.resolver.ts
Normal file
18
src/GraphQL/resolvers/test.resolver.ts
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
import { Query, Resolver, Mutation, Arg } from 'type-graphql';
|
||||
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
||||
|
||||
@Resolver(() => Test)
|
||||
export class TestResolver {
|
||||
@Query(() => Test)
|
||||
async test() {
|
||||
return {};
|
||||
}
|
||||
|
||||
@Mutation(() => TestMutation)
|
||||
async testMutation() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
module.exports = `
|
||||
|
||||
"""Test Query"""
|
||||
type Test {
|
||||
test: String
|
||||
}
|
||||
|
||||
"""Esta es la Data de LogIn, Si los datos no son correctos devuelve el usuario Null y la conexion en False"""
|
||||
type TestMutation {
|
||||
testMutation(text: String): String
|
||||
}
|
||||
|
||||
`
|
@ -1,17 +1,10 @@
|
||||
import { makeExecutableSchema } from '@graphql-tools/schema';
|
||||
import resolvers from'@GraphQL/resolvers';
|
||||
import Test from '@GraphQL/schema/Test.gql';
|
||||
'use strict'
|
||||
|
||||
// The GraphQL schema
|
||||
const rootTypes = `
|
||||
type Query {
|
||||
test: Test
|
||||
}
|
||||
type Mutation {
|
||||
testMutation: TestMutation
|
||||
}
|
||||
`;
|
||||
import { buildSchemaSync } from "type-graphql"
|
||||
import { TestResolver } from "@GraphQL/resolvers/test.resolver";
|
||||
|
||||
const typeDefs = [ rootTypes, Test ];
|
||||
|
||||
export default makeExecutableSchema({typeDefs, resolvers});
|
||||
const schema = buildSchemaSync({
|
||||
resolvers: [TestResolver],
|
||||
emitSchemaFile: true,
|
||||
})
|
||||
export default schema
|
36
src/GraphQL/schema/test.schema.ts
Normal file
36
src/GraphQL/schema/test.schema.ts
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
import { Field, ObjectType, Arg } from "type-graphql";
|
||||
import { getTest, addText } from '@controllerGraphQL';
|
||||
|
||||
@ObjectType()
|
||||
export class Test {
|
||||
@Field(() => Text)
|
||||
async text(){
|
||||
return {
|
||||
text: await getTest({})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class Text {
|
||||
@Field()
|
||||
text?: string
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TestMutation {
|
||||
@Field(type => TextMutation)
|
||||
async textMutation(@Arg('text') text?: string){
|
||||
return {
|
||||
text: await addText({text})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TextMutation {
|
||||
@Field()
|
||||
text?: string
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
import express from 'express'; //express
|
||||
import { graphqlHTTP } from 'express-graphql';
|
||||
import { config } from '@config';
|
||||
import schema from '@GraphQL/schema';
|
||||
import schema from '@src/GraphQL/schema';
|
||||
|
||||
|
||||
const server = express.Router();//Router de Express
|
||||
|
||||
@ -17,8 +19,6 @@ server.use(
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
|
||||
// DO NOT DO app.listen() unless we're testing this directly
|
||||
if (require.main === module) {
|
||||
const app = express();
|
||||
|
Reference in New Issue
Block a user