forked from loafle/openapi-generator-original
* Add GraphQL express/apollo server generator * add basic resolvers; adjust parameters/input types * small adjustments and improvements * adjust logger config for GraphQL generators * remove MaxPermSize form bash script as it will be removed from later Java versions; add isNullable utility helper method; Adjust TODOs for graphql implementation * re-created samples for graphql config and server generators * re-added templates for graphql config generator * add graphql-config-petstore bash script * add isNullable utility method * fix javadoc issues * adjust licence headers * rename Generator to Codegen for GraphQL classes * renaming, minor enhancement to graphql generator * add graphql server samples * add windows batch files, rename directory
37 lines
935 B
JavaScript
37 lines
935 B
JavaScript
import express from 'express';
|
|
import {ApolloServer, graphiqlExpress, graphqlExpress} from 'apollo-server-express'
|
|
import combine from 'graphql-combine'
|
|
import path from 'path'
|
|
|
|
const PORT = 4000 || process.env;
|
|
|
|
// Initialize the app
|
|
const app = express();
|
|
|
|
// Get combined typeDefs and resolvers object
|
|
const {typeDefs, resolvers} = combine({
|
|
// TypeDefs glob pattern
|
|
typeDefs: path.join(__dirname, '**/*.graphql'),
|
|
|
|
// Resolvers glob pattern
|
|
resolvers: path.join(__dirname, 'api/*_resolver.js')
|
|
});
|
|
|
|
// GraphQL: Schema
|
|
const server = new ApolloServer({
|
|
typeDefs: typeDefs,
|
|
resolvers: resolvers,
|
|
playground: {
|
|
endpoint: `http://localhost:${PORT}/graphql`,
|
|
settings: {
|
|
'editor.theme': 'light'
|
|
}
|
|
}
|
|
});
|
|
|
|
server.applyMiddleware({app: app});
|
|
|
|
// Start the server
|
|
app.listen(PORT, () => {
|
|
console.log(`You can reach GraphQL at: http://localhost:${PORT}/graphql`);
|
|
}); |