-
Notifications
You must be signed in to change notification settings - Fork 0
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 lambdas #58
Fix lambdas #58
Conversation
Also make SERVER_PORT env var optional.
Deploy preview for lgtmeme ready! Built with commit 8c2b3f1 |
The S3 domain issue, I think, is from us using the |
@@ -4,6 +4,9 @@ | |||
|
|||
# The query root for LGTMeme. | |||
type Query { | |||
# A simple ping/pong used for testing | |||
herro: String! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running part of an introspection query would achieve pretty much the same thing. Being able to type herro though is pretty easy
{
__schema {
types {
name
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.resolve(process.cwd(), 'src', 'schema.graphql'), | ||
'utf8', | ||
); | ||
// $FlowFixMe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool i couldn't figure out how to get that to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah turns out Netlify compiles one giant JS file, and copies the file to some virtualized environment to run. Nothing else is copied over, so we have to import everything we need at build time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats what i thinking we had to do though this is much more elegant than what i had in mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what did you have in mind? I tried copying stuff over but Netlify's build process just doesn't care about anything in the directory. It has to be in the JS file. Or I just didn't know what special thing to invoke to make that work.
|
||
const connection = await connect(); | ||
console.log(`Connected to MongoDB at ${urlWithoutPassword}`); // eslint-disable-line no-console | ||
|
||
createApp(connection, s3Storage).listen( | ||
SERVER_PORT, | ||
() => console.log(`Listening on ${SERVER_PORT}.`), // eslint-disable-line no-console | ||
nullthrows(DEBUG_SERVER_PORT), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought we had invariant
for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invariant
doesn't return what you pass into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subtle
|
||
// Must disconnect, otherwise a lingering outbound connection makes lambda | ||
// think we aren't done, and not return the request. | ||
await disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something to try out later that reuses connections apparently http://mongoosejs.com/docs/lambda.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were a few things done here to make lambdas happy:
disconnect()
from mongo before returning results. Turns out each function cannot leave lingering connections.netlify.toml
, since that's the only place environment variables are pulled from at runtime. But we don't want to hardcode secrets into the file and commit them, so there's a script to get the build-time environment variables and replaces the placeholders innetlify.toml
with actual values. BUT running lambdas in dev also uses those, which means the "PLACEHOLDER" strings actually override dev env variables, so a separate set of environment variables are used for prod.Other small things:
S3StorageConfig
intoenv
to centralize where env fetching was happening.herro
test graphql query to make testing easier.Go to
https://oliverzheng-lambdass--lgtmeme.netlify.com/.netlify/functions/graphql?query={node(id:%20%22bWVtZTo1YjE3MzEzN2Y0NjE5MjBkMDdhYjA5ZTA6NWIxOWNhYWVhNDNiMTU1YzVmZjU3Zjlj%22){id,...on%20Meme{macro}}}
and see