Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded dependencies #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions graphql/PaintingType.js

This file was deleted.

26 changes: 0 additions & 26 deletions graphql/schema.js

This file was deleted.

84 changes: 39 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const hapi = require('hapi');
const Hapi = require('@hapi/hapi');
const mongoose = require('mongoose');
const { graphqlHapi, graphiqlHapi } = require('apollo-server-hapi');
const schema = require('./graphql/schema');
const { ApolloServer, gql } = require('apollo-server');
const Painting = require('./models/Painting');

/* swagger section */
Expand All @@ -10,21 +9,46 @@ const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package');


const server = hapi.server({
port: 4000,
host: 'localhost'
});

mongoose.connect('mongodb://indrek:[email protected]:31090/powerful-api');

mongoose.connection.once('open', () => {
console.log('connected to database');
});

const init = async () => {
// The GraphQL schema
const typeDefs = gql`
type Painting {
id: String
name: String
url: String
technique: String
}
type Query {
paintings: [Painting]
paintingsById(id: ID!): Painting
}
`;

// A map of functions which return data for the schema.
const resolvers = {
Query: {
paintings: () => Painting.find(),
paintingsById: (obj, args) => Painting.findById(args.id)
},
};

async function StartServer() {
const server = new ApolloServer({ typeDefs, resolvers });

await server.register([
const app = new Hapi.server({
port: 3000
});

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});

await app.register([
Inert,
Vision,
{
Expand All @@ -38,34 +62,7 @@ const init = async () => {
}
]);

await server.register({
plugin: graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: {
endpointURL: '/graphql'
},
route: {
cors: true
}
}
});

await server.register({
plugin: graphqlHapi,
options: {
path: '/graphql',
graphqlOptions: {
schema
},
route: {
cors: true
}
}
});


server.route([
app.route([
{
method: 'GET',
path: '/api/v1/paintings',
Expand All @@ -91,21 +88,18 @@ const init = async () => {
url,
technique
});

return painting.save();
}
}
]);
await app.start();
}

await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
StartServer().catch(error => console.log(error));

process.on('unHandledRejection', (err) => {
if (err) {
console.log(err);
process.exit(1);
}
});

init();
Loading