https://github.com/kaiwedekind/vertx-graphql-example
https://github.com/kaiwedekind/vertx-graphql-example
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kaiwedekind/vertx-graphql-example
- Owner: KaiWedekind
- Created: 2018-10-31T06:12:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-17T20:52:55.000Z (over 6 years ago)
- Last Synced: 2025-03-09T22:41:25.713Z (7 months ago)
- Language: JavaScript
- Size: 34.5 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
GraphQL HTTP Server Middleware
==============================Create a GraphQL HTTP server with [Vert.x](https://github.com/reactiverse/es4x).
## Installation
```sh
npm install --save vertx-graphql
```## Simple Setup
```js
///
// @ts-checkimport {
Router,
BodyHandler,
StaticHandler
} from '@vertx/web';import {
VertxGraphQL
} from './vertx-graphql';const app = Router.router(vertx);
const PORT = 9100;app.route().handler(BodyHandler.create().handle);
app.route().handler(StaticHandler.create().handle);// The GraphQL schema
const typeDefs = `
input MessageInput {
content: String
author: String
}type Message {
id: ID!
content: String
author: String
}type Query {
hello: String
welcome: String
}type Mutation {
createMessage(input: MessageInput): Message
}
`;const resolvers = {
Query: {
hello: () => 'Hello world!',
welcome: () => 'Welcome to Vert.x GraphQL!',
},
Mutation: {
createMessage: ({ input }, context) => {
return {
id: 123,
content: 'Content XYZ',
author: 'Me'
}
}
}
};const context = {
mongoDB: true
}const graphQL = new VertxGraphQL({ typeDefs, resolvers, context });
graphQL.applyMiddleware({
app,
graphqlEndpoint: '/graphql',
graphiqlEndpoint: '/explorer',
graphiqlUI: {
// title: 'Middot Explorer',
// favicon: './images/favicon.ico',
// stylesheet: './css/graphiql-custom.css'
}
});app.route().handler((ctx) => {
ctx.response().end('Hello from Vert.x GraphQL!');
});vertx.createHttpServer()
.requestHandler((result) => {
return app.accept(result);
})
.listen(PORT, () => {
console.log('Server started')
});
```---
[GraphQL.js](https://github.com/graphql/graphql-js)
[GraphiQL](https://github.com/graphql/graphiql)
[Themes](https://codemirror.net/theme/)
[Subscriptions](https://www.apollographql.com/docs/graphql-subscriptions/)
[GrapqhQL Tracing](https://github.com/apollographql/apollo-server/tree/master/packages/apollo-tracing)
[Subscription-Operation-Definitions](https://facebook.github.io/graphql/draft/#sec-Subscription-Operation-Definitions)
[Examples](https://github.com/vert-x3/vertx-examples)
### Typescript
This package includes [Typescript](http://www.typescriptlang.org/) typedefinitions and your IDE should find then automatically.
When working in a project you can enable type hinting for the runtime as:
```js
///
// @ts-check// Your JavaScript / TypeScript code here...
```## Links
* [Eclipse Vert.x](https://vertx.io)
* [ES4X](https://reactiverse.io/es4x)