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

Implementation of Apollo Server 2 for Google Cloud Functions #1446

Merged
merged 10 commits into from Aug 20, 2018

Conversation

reaktivo
Copy link
Contributor

@reaktivo reaktivo commented Jul 28, 2018

This PR adds support for Google Cloud Functions (based on the Lambda one), you can check out a minimal but working example at: https://europe-west1-test-project-bdb0d.cloudfunctions.net/test-apollo-server-cloud-function

This issue fixes #1402

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@apollo-cla
Copy link

@reaktivo: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@ghost ghost added ⛲️ feature New addition or enhancement to existing solutions labels Jul 28, 2018
@reaktivo reaktivo force-pushed the google-cloud-function-support branch from dff1d09 to 4861872 Compare July 28, 2018 16:17
@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Jul 28, 2018
@reaktivo reaktivo force-pushed the google-cloud-function-support branch from fcd29db to 30174e2 Compare July 30, 2018 11:35
@reaktivo reaktivo changed the title WIP: Initial implementation of Apollo Server 2 for gcf Implementation of Apollo Server 2 for Google Cloud Functions Jul 30, 2018
@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Jul 30, 2018
@reaktivo reaktivo force-pushed the google-cloud-function-support branch from 30174e2 to 2424dfa Compare July 31, 2018 11:25
@hwillson hwillson requested review from evans and hwillson July 31, 2018 12:59
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome @reaktivo - everything here looks great! The only small suggestion I have is to maybe rename the gqlApollo.ts and gqlApollo.test.ts files to be more inline with the naming used by the other integrations. The Lambda integration uses lambdaApollo.ts for example, CloudFlare uses cloudflareApollo.ts, etc. Maybe something like gcfApollo.ts or googleCloudApollo.ts? Honestly, this is a super minor thing, and I don't really consider it essential to getting this approved. Thanks vey much for working on this!

@reaktivo
Copy link
Contributor Author

Hah! That was a funny slip up, I meant them to be gcfApollo.ts but I think having them as googleCloudApollo.ts makes them way more explicit any way, I'll update

@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Jul 31, 2018
Copy link
Contributor

@evans evans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reaktivo Thank you so much for the PR! Super excited about GCF support.

I left a couple of comments on the documentation that would help people start using the package. Can't wait to get this out the door 🎉


## Getting request info

To read information about the current request from the API Gateway event (HTTP headers, HTTP method, body, path, ...) or the current Google Cloud Function (Function Name, Function Version, awsRequestId, time remaining, ...) use the options function. This way they can be passed to your schema resolvers using the context option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awsRequestId seems out of place. I'm not super familiar with GCF, so it totally could be a thing!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed mentions to aws and simplified this section

#### 2. Configure your Cloud function and deploy

Set the _Function to execute_ option to _handler_
and deploy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick section here on how to deploy the GCF would be incredible! Hopefully it includes a link to some of GCF's documentation as well

In the lambda world, we have to do some special things to ensure that all requests are piped to the handler, so that the OPTIONS request to cors is properly routed. My naive assumption is that GCF has similar configuration requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a bit more details. But in general GCF doesn't requiring much additional configuration


#### 1. Write the API handlers

In a file named `graphql.js`, place the following code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a lambda environment, the specific file was necessary, since the configuration referenced graphql.handler. Does GCF have the same sort of dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed it's actually necessary for the js file to be named index.js since the configuration only allows setting the directory of the function and not the file itself.

@reaktivo
Copy link
Contributor Author

reaktivo commented Aug 2, 2018

The changes are on their way, thanks for the feedback!

@reaktivo reaktivo force-pushed the google-cloud-function-support branch from bd9b26b to 22d186c Compare August 2, 2018 14:07
@reaktivo
Copy link
Contributor Author

reaktivo commented Aug 2, 2018

@evans @hwillson Updated!

@reaktivo reaktivo force-pushed the google-cloud-function-support branch 2 times, most recently from 4cf1fd5 to 784cd5f Compare August 6, 2018 13:22
@reaktivo reaktivo force-pushed the google-cloud-function-support branch from 784cd5f to 25fa7bd Compare August 20, 2018 07:44
@hwillson
Copy link
Member

Thanks for these changes @reaktivo. We should be all set here, so LGTM!

@hwillson hwillson merged commit 724d9ff into apollographql:master Aug 20, 2018
abernix added a commit that referenced this pull request Nov 12, 2018
The `apollo-server-cloud-functions` has been been mis-referenced (or
referenced inconsistently) since its original inception in #1446 when its
package directory was `apollo-server-cloud-function` (singular!) and the
`package.json` referenced the plural form (`apollo-server-cloud-functions`):

724d9ff0#diff-e1d725fd66f7e9ef5251abf0437a09ca

These references have been mostly fixed in the READMEs and supporting
documentation, but the underlying monorepo directory structure has still not
been fixed, which I'm sure contributed to this module being overlooked and
unreferenced in the move to TypeScript project references in #1772.

Additionally, the lack of referencing in the monorepo's TS config has
resulted in it being broken in the most recent 2.2.0 release, as reported by
@pyros2097 and @thetre97 in: #1896 (comment)

This should fix that by properly adding the TypeScript project references.
abernix added a commit that referenced this pull request Nov 12, 2018
…1948)

* Add correct project references for `apollo-server-cloud-functions`.

The `apollo-server-cloud-functions` has been been mis-referenced (or
referenced inconsistently) since its original inception in #1446 when its
package directory was `apollo-server-cloud-function` (singular!) and the
`package.json` referenced the plural form (`apollo-server-cloud-functions`):

724d9ff0#diff-e1d725fd66f7e9ef5251abf0437a09ca

These references have been mostly fixed in the READMEs and supporting
documentation, but the underlying monorepo directory structure has still not
been fixed, which I'm sure contributed to this module being overlooked and
unreferenced in the move to TypeScript project references in #1772.

Additionally, the lack of referencing in the monorepo's TS config has
resulted in it being broken in the most recent 2.2.0 release, as reported by
@pyros2097 and @thetre97 in: #1896 (comment)

This should fix that by properly adding the TypeScript project references.

* Sorting.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⛲️ feature New addition or enhancement to existing solutions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serverless with Google Cloud Function
4 participants