Hi,
I’ve been hosting for an e-commerce startup project and building the whole app with Netilfy. I really like Netlify’s simplicity
As a matter of fact, I’m actually an entry full-stack dev and facing a lot of challenges these days as we integrating apollo graphql.
So here is one of the challenges:
I’m not sure if this is the right way of building multiple lambda functions. (have two functions: product, gateway each has its own folder and package.json)
This setup anyhow builds and serves both functions(had to add -p since netlify lambda doesn’t’ automatically serve multiple functions in different port)
Is there a way to build in on script like build:lambda: "netlify-lambda build without building each function?
Also, I assume that when it’s actually being deployed Netlify doesn’t use my serve script but uses it’s own proxying. Is that correct?
Hey @peter-wd-1,
In terms of deploying your functions, our buildbot will automatically bundle your functions if you have a setup like this, where this is your root directory:
src/
|__ App.js
functions-dir/
|__ product.js
|__ gateway.js
package.json <--- includes dependencies for functions
netlify.toml
and netlify.toml declares the functions directory:
[build]
...
functions = "functions-dir/"
So you can use netlify-lambda for local testing, but I did want to let you know that it’s not necessary for deploying to production. Once you deploy your functions, you can call them from the client side like this (from the Apollo docs):
// src/App.js
import ApolloClient from "apollo-boost";
const client = new ApolloClient({
uri: "/.netlify/functions/graphql"
});
Let us know if that helps or if you have follow-up questions! And if there’s a question about a specific/site deploy, please share a URL to those so we can take a look
He @jen
Thank you for your detailed response
I’ve been working out with this issue for almost a week… Now I’ve set the whole thing working smoothly with Netlify Dev(not on production deploy though).
I’ve decided to use the script build strategy because as the functions getting lager I thought it would be more navigable to have its own folders for each function:
I’m creating a repo for setting up gateway & netlify lambda. It’s running on here.
That said, I have an issue when its deployed because Netlify deploys only one function(here with the folder structure above would be federated-graphql-a). The rest of two functions are not deployed.
this uses the built-in “zip and ship” functionality as opposed to netlify-lambda, but you still get to break out functions into their own folders with their own dependencies
The longer story
There are a couple different issues happening at once and the best resource I can point you to is this extensive conversation about different ways you can build functions (zip and ship, manually zip, netlify-lambda):
I’d really recommend reviewing that if you want to get this working with netlify-lambda. I believe the core of the issue is that your function dependencies are not being automatically bundled with the netlify-lambda build command; you will need to install the function dependencies, one command at a time or with a script.
Hope you find this helpful! Let us know if you have any other questions.