Merge remote-tracking branch 'upstream/master' into graphiql-function

This commit is contained in:
Daniel Rinehart 2017-06-16 11:00:42 -04:00
commit 20763ba076
17 changed files with 140 additions and 64 deletions

View file

@ -3,6 +3,9 @@
### VNEXT
* Allow GraphiQLOptions to be a function ([@NeoPhi](https://github.com/NeoPhi)) on [#426](https://github.com/apollographql/graphql-server/pull/426)
### v0.8.5
* Fix: graphql-server-micro now properly returns response promises [#401](https://github.com/apollographql/graphql-server/pull/401)
### v0.8.4
### v0.8.3
### v0.8.2

View file

@ -1,6 +1,6 @@
{
"lerna": "2.0.0-rc.4",
"version": "0.8.4",
"version": "0.8.5",
"changelog": {
"repo": "apollostack/graphql-server",
"labels": {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-core",
"version": "0.8.4",
"version": "0.8.5",
"description": "Core engine for Apollo GraphQL server",
"main": "dist/index.js",
"scripts": {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-express",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for Express and Connect",
"main": "dist/index.js",
"scripts": {
@ -26,8 +26,8 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"@types/body-parser": "1.16.3",
@ -38,7 +38,7 @@
"connect": "^3.6.2",
"connect-query": "^1.0.0",
"express": "^4.15.3",
"graphql-server-integration-testsuite": "^0.8.4",
"graphql-server-integration-testsuite": "^0.8.5",
"multer": "^1.3.0"
},
"peerDependencies": {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-hapi",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for Hapi",
"main": "dist/index.js",
"scripts": {
@ -26,14 +26,14 @@
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"boom": "^5.1.0",
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"@types/boom": "4.3.2",
"@types/graphql": "^0.9.1",
"@types/hapi": "^16.1.4",
"graphql-server-integration-testsuite": "^0.8.4",
"graphql-server-integration-testsuite": "^0.8.5",
"hapi": "^16.4.3"
},
"peerDependencies": {

View file

@ -1,7 +1,7 @@
{
"name": "graphql-server-integration-testsuite",
"private": true,
"version": "0.8.4",
"version": "0.8.5",
"description": "Apollo Server Integrations testsuite",
"main": "dist/index.js",
"scripts": {
@ -20,9 +20,9 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2",
"graphql-server-module-operation-store": "^0.8.2",
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5",
"graphql-server-module-operation-store": "^0.8.5",
"supertest": "^3.0.0",
"supertest-as-promised": "^4.0.0"
},

View file

@ -843,5 +843,20 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => {
});
});
});
describe('server setup', () => {
it('throws error on 404 routes', () => {
app = createApp();
const query = {
query: '{ testString }',
};
const req = request(app)
.get(`/bogus-route?${querystring.stringify(query)}`);
return req.then((res) => {
expect(res.status).to.equal(404);
});
});
});
});
};

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-koa",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for Koa",
"main": "dist/index.js",
"scripts": {
@ -25,14 +25,14 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"@types/koa": "^2.0.39",
"@types/koa-bodyparser": "^3.0.23",
"@types/koa-router": "^7.0.22",
"graphql-server-integration-testsuite": "^0.8.4",
"graphql-server-integration-testsuite": "^0.8.5",
"koa": "^2.2.0",
"koa-bodyparser": "^4.2.0",
"koa-router": "^7.2.0"

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-lambda",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for AWS Lambda",
"main": "dist/index.js",
"scripts": {
@ -25,13 +25,13 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"@types/aws-lambda": "0.0.10",
"@types/graphql": "^0.9.1",
"graphql-server-integration-testsuite": "^0.8.4"
"graphql-server-integration-testsuite": "^0.8.5"
},
"peerDependencies": {
"graphql": "^0.9.0 || ^0.10.1"

View file

@ -6,19 +6,28 @@ import 'mocha';
import * as url from 'url';
function createLambda(options: CreateAppOptions = {}) {
let handler,
let route,
handler,
callback,
event,
context;
options.graphqlOptions = options.graphqlOptions || { schema: Schema };
if (options.graphiqlOptions ) {
route = '/graphiql';
handler = graphiqlLambda( options.graphiqlOptions );
} else {
route = '/graphql';
handler = graphqlLambda( options.graphqlOptions );
}
return function(req, res) {
if (!req.url.startsWith(route)) {
res.statusCode = 404;
res.end();
return;
}
let body = '';
req.on('data', function (chunk) {
body += chunk;

View file

@ -1,3 +1,26 @@
# graphql-server-micro
This is the [Micro](https://github.com/zeit/micro) integration for the Apollo community GraphQL Server. [Read the docs.](http://dev.apollodata.com/tools/apollo-server/index.html)
## Example
```typescript
import { microGraphiql, microGraphql } from "graphql-server-micro";
import micro, { send } from "micro";
import { get, post, router } from "microrouter";
import schema from "./schema";
const graphqlHandler = microGraphql({ schema });
const graphiqlHandler = microGraphiql({ endpointURL: "/graphql" });
const server = micro(
router(
get("/graphql", graphqlHandler),
post("/graphql", graphqlHandler),
get("/graphiql", graphiqlHandler),
(req, res) => send(res, 404, "not found"),
),
);
server.listen(3000);
```

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-micro",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for Micro",
"main": "dist/index.js",
"scripts": {
@ -25,19 +25,21 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"graphql-server-integration-testsuite": "^0.8.4",
"micro": "^7.3.3"
"graphql-server-integration-testsuite": "^0.8.5",
"micro": "^7.3.3",
"microrouter": "^2.1.1"
},
"peerDependencies": {
"graphql": "^0.9.0 || ^0.10.1",
"micro": "^7.3.3"
},
"optionalDependencies": {
"@types/graphql": "^0.9.1"
"@types/graphql": "^0.9.1",
"@types/micro": "^7.3.0"
},
"typings": "dist/index.d.ts",
"typescript": {

View file

@ -1,16 +1,39 @@
import { microGraphql, microGraphiql } from './microApollo';
import 'mocha';
import * as micro from 'micro';
import testSuite, { schema as Schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
import micro, { send } from 'micro';
import { router, get, post, put, patch, del, head, options as opts } from 'microrouter';
import testSuite, { schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
function createApp(options: CreateAppOptions) {
if (options && options.graphiqlOptions ) {
return micro(microGraphiql( options.graphiqlOptions ));
} else {
const graphqlOptions = (options && options.graphqlOptions) || { schema: Schema };
return micro(microGraphql(graphqlOptions));
}
const graphqlOptions = (options && options.graphqlOptions) || { schema };
const graphiqlOptions = (options && options.graphiqlOptions) || { endpointURL: '/graphql' };
const graphqlHandler = microGraphql(graphqlOptions);
const graphiqlHandler = microGraphiql(graphiqlOptions);
return micro(
router(
get('/graphql', graphqlHandler),
post('/graphql', graphqlHandler),
put('/graphql', graphqlHandler),
patch('/graphql', graphqlHandler),
del('/graphql', graphqlHandler),
head('/graphql', graphqlHandler),
opts('/graphql', graphqlHandler),
get('/graphiql', graphiqlHandler),
post('/graphiql', graphiqlHandler),
put('/graphiql', graphiqlHandler),
patch('/graphiql', graphiqlHandler),
del('/graphiql', graphiqlHandler),
head('/graphiql', graphiqlHandler),
opts('/graphiql', graphiqlHandler),
(req, res) => send(res, 404, 'not found'),
),
);
}
describe('integration:Micro', () => {

View file

@ -1,6 +1,6 @@
import { GraphQLOptions, HttpQueryError, runHttpQuery } from 'graphql-server-core';
import * as GraphiQL from 'graphql-server-module-graphiql';
import { json } from 'micro';
import { createError, json, RequestHandler } from 'micro';
import * as url from 'url';
import {IncomingMessage, ServerResponse} from 'http';
@ -8,7 +8,7 @@ export interface MicroGraphQLOptionsFunction {
(req?: IncomingMessage): GraphQLOptions | Promise<GraphQLOptions>;
}
export function microGraphql(options: GraphQLOptions | MicroGraphQLOptionsFunction) {
export function microGraphql(options: GraphQLOptions | MicroGraphQLOptionsFunction): RequestHandler {
if (!options) {
throw new Error('Apollo Server requires options.');
}
@ -29,29 +29,30 @@ export function microGraphql(options: GraphQLOptions | MicroGraphQLOptionsFuncti
query = url.parse(req.url, true).query;
}
runHttpQuery([req, res], {
method: req.method,
options: options,
query: query,
}).then((gqlResponse) => {
try {
const gqlResponse = await runHttpQuery([req, res], {
method: req.method,
options: options,
query: query,
});
res.setHeader('Content-Type', 'application/json');
res.write(gqlResponse);
res.end();
}, (error: HttpQueryError) => {
if ( 'HttpQueryError' !== error.name ) {
throw error;
return gqlResponse;
} catch (error) {
if ('HttpQueryError' === error.name) {
if (error.headers) {
Object.keys(error.headers).forEach((header) => {
res.setHeader(header, error.headers[header]);
});
}
}
if ( error.headers ) {
Object.keys(error.headers).forEach((header) => {
res.setHeader(header, error.headers[header]);
});
if (!error.statusCode) {
error.statusCode = 500;
}
res.statusCode = error.statusCode;
res.write(error.message);
res.end();
});
throw error;
}
};
}
@ -59,7 +60,7 @@ export interface MicroGraphiQLOptionsFunction {
(req?: IncomingMessage): GraphiQL.GraphiQLData | Promise<GraphiQL.GraphiQLData>;
}
export function microGraphiql(options: GraphiQL.GraphiQLData | MicroGraphiQLOptionsFunction) {
export function microGraphiql(options: GraphiQL.GraphiQLData | MicroGraphiQLOptionsFunction): RequestHandler {
return (req: IncomingMessage, res: ServerResponse) => {
const query = req.url && url.parse(req.url, true).query || {};
GraphiQL.resolveGraphiQLString(query, options, req).then(graphiqlString => {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-module-graphiql",
"version": "0.8.2",
"version": "0.8.5",
"description": "GraphiQL renderer for Apollo GraphQL Server",
"main": "dist/index.js",
"scripts": {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-module-operation-store",
"version": "0.8.2",
"version": "0.8.5",
"description": "Persisted operation store module for Apollo GraphQL Servers",
"main": "dist/index.js",
"scripts": {

View file

@ -1,6 +1,6 @@
{
"name": "graphql-server-restify",
"version": "0.8.4",
"version": "0.8.5",
"description": "Production-ready Node.js GraphQL server for Restify",
"main": "dist/index.js",
"scripts": {
@ -25,12 +25,12 @@
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
"graphql-server-core": "^0.8.4",
"graphql-server-module-graphiql": "^0.8.2"
"graphql-server-core": "^0.8.5",
"graphql-server-module-graphiql": "^0.8.5"
},
"devDependencies": {
"@types/restify": "^4.3.2",
"graphql-server-integration-testsuite": "^0.8.4",
"graphql-server-integration-testsuite": "^0.8.5",
"restify": "^4.3.0"
},
"peerDependencies": {