PR-757991: adding typegraphql.

This commit is contained in:
2023-03-10 13:18:24 +00:00
parent 6ff6edaaf4
commit 4ffc696ee4
14 changed files with 392 additions and 114 deletions

View File

@ -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;

View 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 {};
}
}

View File

@ -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
}
`

View File

@ -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

View 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
}

View File

@ -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();