mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
improve hapi api
This commit is contained in:
parent
0e1c06ef57
commit
3a39e96f20
2 changed files with 14 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
import * as hapi from 'hapi';
|
||||
import { HapiApollo } from './hapiApollo';
|
||||
import { ApolloHAPI, GraphiQLHAPI } from './hapiApollo';
|
||||
|
||||
import testSuite, { Schema, CreateAppOptions } from './integrations.test';
|
||||
|
||||
|
@ -12,12 +12,18 @@ function createApp(options: CreateAppOptions = {}) {
|
|||
});
|
||||
|
||||
server.register({
|
||||
register: new HapiApollo(),
|
||||
register: new ApolloHAPI(),
|
||||
options: { schema: Schema },
|
||||
routes: { prefix: '/graphql' },
|
||||
});
|
||||
|
||||
return server;
|
||||
server.register({
|
||||
register: new GraphiQLHAPI(),
|
||||
options: { endpointURL: '/graphql' },
|
||||
routes: { prefix: '/graphql' },
|
||||
});
|
||||
|
||||
return server.listener;
|
||||
}
|
||||
|
||||
testSuite(createApp);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as hapi from 'hapi';
|
||||
import GraphiQL from '../modules/renderGraphiQL';
|
||||
import * as GraphiQL from '../modules/renderGraphiQL';
|
||||
import { runQuery } from '../core/runQuery';
|
||||
import apolloOptions from './apolloOptions';
|
||||
|
||||
|
@ -9,7 +9,7 @@ export interface IRegister {
|
|||
attributes?: any;
|
||||
}
|
||||
|
||||
export class HapiApollo {
|
||||
export class ApolloHAPI {
|
||||
constructor() {
|
||||
this.register.attributes = {
|
||||
name: 'graphql',
|
||||
|
@ -26,6 +26,7 @@ export class HapiApollo {
|
|||
schema: options.schema,
|
||||
query: request.payload,
|
||||
}).then(gqlResponse => {
|
||||
console.dir(gqlResponse);
|
||||
reply({ data: gqlResponse.data });
|
||||
}).catch(errors => {
|
||||
reply({ errors: errors }).code(500);
|
||||
|
@ -36,7 +37,7 @@ export class HapiApollo {
|
|||
}
|
||||
}
|
||||
|
||||
export class HapiGraphiQL {
|
||||
export class GraphiQLHAPI {
|
||||
constructor() {
|
||||
this.register.attributes = {
|
||||
name: 'graphiql',
|
||||
|
@ -47,7 +48,7 @@ export class HapiGraphiQL {
|
|||
public register: IRegister = (server: hapi.Server, options: GraphiQL.GraphiQLData, next) => {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/graphiql',
|
||||
path: '/',
|
||||
handler: (request, reply) => {
|
||||
const q = request.query || {};
|
||||
const query = q.query || '';
|
||||
|
|
Loading…
Add table
Reference in a new issue