mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-07-01 02:08:27 -06:00
PR-448199:
Moving Server to src directory.
This commit is contained in:
23
src/GraphQL/resolvers/index.ts
Normal file
23
src/GraphQL/resolvers/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
import { getTest, addText } from '../../controllers/controllerGraphQL';
|
||||
|
||||
// A map of functions which return data for the schema.
|
||||
const resolvers = {
|
||||
Query: {
|
||||
// eslint-disable-next-line
|
||||
test: (rootValue, args, context) => ({}),
|
||||
},
|
||||
Mutation: {
|
||||
// eslint-disable-next-line
|
||||
testMutation: (rootValue, args, context) => ({}),
|
||||
},
|
||||
Test: {
|
||||
test: (rootValue, args, context) => getTest(rootValue, args, context)
|
||||
},
|
||||
TestMutation: {
|
||||
testMutation: (rootValue, args, context) => addText(rootValue, args, context)
|
||||
}
|
||||
};
|
||||
|
||||
export default resolvers;
|
13
src/GraphQL/schema/Test.gql
Normal file
13
src/GraphQL/schema/Test.gql
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
||||
}
|
||||
|
||||
`
|
17
src/GraphQL/schema/index.ts
Normal file
17
src/GraphQL/schema/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { makeExecutableSchema } from '@graphql-tools/schema';
|
||||
import resolvers from'../resolvers';
|
||||
import Test from './Test.gql';
|
||||
|
||||
// The GraphQL schema
|
||||
const rootTypes = `
|
||||
type Query {
|
||||
test: Test
|
||||
}
|
||||
type Mutation {
|
||||
testMutation: TestMutation
|
||||
}
|
||||
`;
|
||||
|
||||
const typeDefs = [ rootTypes, Test ];
|
||||
|
||||
export default makeExecutableSchema({typeDefs, resolvers});
|
30
src/GraphQL/server.ts
Normal file
30
src/GraphQL/server.ts
Normal file
@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
import express from 'express'; //express
|
||||
import { graphqlHTTP } from 'express-graphql';
|
||||
import { config } from '../../config';
|
||||
import schema from './schema';
|
||||
|
||||
const server = express.Router();//Router de Express
|
||||
|
||||
server.use(
|
||||
'/',
|
||||
graphqlHTTP( (req, res) => {
|
||||
return {
|
||||
schema,
|
||||
graphiql: config.graphiQL,
|
||||
context: { req, res }
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
|
||||
// DO NOT DO app.listen() unless we're testing this directly
|
||||
if (require.main === module) {
|
||||
server.listen((process.env.PORT || 4000), () => {
|
||||
console.log(`Iniciando Express en el puerto 4000${server.graphqlPath}`); /*${app.get('port')}*/
|
||||
});
|
||||
}
|
||||
|
||||
// Instead do export the app:
|
||||
export default server;
|
Reference in New Issue
Block a user