Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cloud functions tests #1611

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All of the packages in the `apollo-server` repo are released with the same versi
- Update `graphql-playground-html` to 1.7.4 [#1586](https://github.com/apollographql/apollo-server/pull/1586)
- Add support for `graphql-js` v14 by augmenting typeDefs with the `@cacheControl` directive so SDL validation doesn't fail [#1595](https://github.com/apollographql/apollo-server/pull/1595)
- Add `node-fetch` extensions typing to `RequestInit` [#1602](https://github.com/apollographql/apollo-server/pull/1602)
- Fix `apollo-server-cloud-functions` tests [#1611](https://github.com/apollographql/apollo-server/pull/1611/)

### v2.0.5

Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-cloud-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"dependencies": {
"@apollographql/graphql-playground-html": "^1.6.0",
"apollo-server-core": "2.0.0",
"apollo-server-env": "2.0.0",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-env": "file:../apollo-server-env",
"graphql-tools": "^3.0.4"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion packages/apollo-server-cloud-function/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export class ApolloServer extends ApolloServerBase {
}

return (req: Request, res: Response) => {
if (req.url !== '') {
res.status(404).end();
return;
}

if (cors) {
if (typeof cors.origin === 'string') {
res.set('Access-Control-Allow-Origin', cors.origin);
Expand All @@ -108,7 +113,8 @@ export class ApolloServer extends ApolloServerBase {
}

if (this.playgroundOptions && req.method === 'GET') {
if (req.accepts('text/html')) {
const acceptHeader = req.headers['accept'] as string;
if (acceptHeader.includes('text/html')) {
const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
endpoint: req.get('referer'),
...this.playgroundOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ApolloServer } from '../ApolloServer';
import testSuite, {
schema as Schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
import { Config } from 'apollo-server-core';
import * as express from 'express';
import * as bodyParser from 'body-parser';

const createCloudFunction = (options: CreateAppOptions = {}) => {
const handler = new ApolloServer(
(options.graphqlOptions as Config) || { schema: Schema },
).createHandler();

// We use Express to simulate the Google Cloud
// Function like environment
const app = express();
app.use(bodyParser.json());
app.use(handler);
return app;
};

describe('integration:CloudFunction', () => {
testSuite(createCloudFunction);
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function graphqlCloudFunction(options: GraphQLOptions): any {
runHttpQuery([req, res], {
method: req.method,
options: options,
query: req.method === 'POST' ? req.body : (req.query as any),
query:
req.method === 'POST' && Object.keys(req.body).length > 0
? req.body
: (req.query as any),
request: {
url: req.url,
method: req.method,
Expand All @@ -40,14 +43,10 @@ export function graphqlCloudFunction(options: GraphQLOptions): any {
.send(graphqlResponse);
},
(error: HttpQueryError) => {
console.log('Error!');
console.log(JSON.stringify(error));
if ('HttpQueryError' !== error.name) {
res.status(500).send(error);
return;
}
console.log('other error');
console.log(JSON.stringify(error));
res
.status(error.statusCode)
.set(error.headers)
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-server-cloud-function/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"lib": ["es2017", "esnext.asynciterable", "dom"]
"outDir": "./dist"
},
"exclude": ["node_modules", "dist"]
"include": ["src/**/*"],
"exclude": ["**/__tests__", "**/__mocks__"]
}