mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11: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 * as hapi from 'hapi';
|
||||||
import { HapiApollo } from './hapiApollo';
|
import { ApolloHAPI, GraphiQLHAPI } from './hapiApollo';
|
||||||
|
|
||||||
import testSuite, { Schema, CreateAppOptions } from './integrations.test';
|
import testSuite, { Schema, CreateAppOptions } from './integrations.test';
|
||||||
|
|
||||||
|
@ -12,12 +12,18 @@ function createApp(options: CreateAppOptions = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
server.register({
|
server.register({
|
||||||
register: new HapiApollo(),
|
register: new ApolloHAPI(),
|
||||||
options: { schema: Schema },
|
options: { schema: Schema },
|
||||||
routes: { prefix: '/graphql' },
|
routes: { prefix: '/graphql' },
|
||||||
});
|
});
|
||||||
|
|
||||||
return server;
|
server.register({
|
||||||
|
register: new GraphiQLHAPI(),
|
||||||
|
options: { endpointURL: '/graphql' },
|
||||||
|
routes: { prefix: '/graphql' },
|
||||||
|
});
|
||||||
|
|
||||||
|
return server.listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
testSuite(createApp);
|
testSuite(createApp);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as hapi from 'hapi';
|
import * as hapi from 'hapi';
|
||||||
import GraphiQL from '../modules/renderGraphiQL';
|
import * as GraphiQL from '../modules/renderGraphiQL';
|
||||||
import { runQuery } from '../core/runQuery';
|
import { runQuery } from '../core/runQuery';
|
||||||
import apolloOptions from './apolloOptions';
|
import apolloOptions from './apolloOptions';
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export interface IRegister {
|
||||||
attributes?: any;
|
attributes?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HapiApollo {
|
export class ApolloHAPI {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.register.attributes = {
|
this.register.attributes = {
|
||||||
name: 'graphql',
|
name: 'graphql',
|
||||||
|
@ -26,6 +26,7 @@ export class HapiApollo {
|
||||||
schema: options.schema,
|
schema: options.schema,
|
||||||
query: request.payload,
|
query: request.payload,
|
||||||
}).then(gqlResponse => {
|
}).then(gqlResponse => {
|
||||||
|
console.dir(gqlResponse);
|
||||||
reply({ data: gqlResponse.data });
|
reply({ data: gqlResponse.data });
|
||||||
}).catch(errors => {
|
}).catch(errors => {
|
||||||
reply({ errors: errors }).code(500);
|
reply({ errors: errors }).code(500);
|
||||||
|
@ -36,7 +37,7 @@ export class HapiApollo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HapiGraphiQL {
|
export class GraphiQLHAPI {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.register.attributes = {
|
this.register.attributes = {
|
||||||
name: 'graphiql',
|
name: 'graphiql',
|
||||||
|
@ -47,7 +48,7 @@ export class HapiGraphiQL {
|
||||||
public register: IRegister = (server: hapi.Server, options: GraphiQL.GraphiQLData, next) => {
|
public register: IRegister = (server: hapi.Server, options: GraphiQL.GraphiQLData, next) => {
|
||||||
server.route({
|
server.route({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/graphiql',
|
path: '/',
|
||||||
handler: (request, reply) => {
|
handler: (request, reply) => {
|
||||||
const q = request.query || {};
|
const q = request.query || {};
|
||||||
const query = q.query || '';
|
const query = q.query || '';
|
||||||
|
|
Loading…
Add table
Reference in a new issue