Hi Gerald,
Thanks for the reply.
My code is not entirely public, but here’s the graphql function code:
const { ApolloServer } = require('apollo-server-lambda')
import { importSchema } from 'graphql-import'
import { prisma } from '../../../database/generated/prisma-client'
import { Repo } from './resolvers/Repo'
import { Deploy } from './resolvers/Deploy'
import { Branch } from './resolvers/Branch'
import { Query } from './resolvers/Query'
import { Mutation } from './resolvers/Mutation'
const path = require('path')
const typeDefs = importSchema(path.resolve('./src/lambda/schema.graphql'))
const resolvers = {
Repo,
Deploy,
Branch,
Query,
Mutation,
}
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ context }) => {
let user
if (context.clientContext.user) {
user = prisma.user({ sub: context.clientContext.user.sub })
}
return {
db: prisma,
user,
}
},
introspection: true,
playground: true,
})
exports.handler = server.createHandler()
The resolvers are all pretty basic resolvers, like so:
import { RepoResolvers } from '../../generated/graphql-server'
import { MyContext } from '../context'
export const Repo: RepoResolvers = {
id: (parent, args, ctx) => parent.id,
name: (parent, args, ctx) => parent.name,
branches: ({ id }, args, ctx: MyContext) => {
return ctx.db.repo({ id }).branches()
},
}
Except the Mutation one has a bit of a nested query:
import { MutationResolvers } from '../../generated/graphql-server'
export const Mutation: MutationResolvers = {
upsertDeploy: async (
root,
{ deployId, branchName, url, status, repoName },
ctx,
) => {
let [repo] = await ctx.db.repoes({
where: {
name: repoName,
},
})
const [branch] = await ctx.db.branches({
where: {
name: branchName,
repo: {
id: (repo && repo.id) || '0',
},
},
})
await ctx.db.upsertRepo({
where: {
id: (repo && repo.id) || '0',
},
create: {
name: repoName,
branches: {
create: {
name: branchName,
deploys: {
create: {
deployId,
url,
status,
},
},
},
},
},
update: {
branches: {
upsert: {
where: {
id: (branch && branch.id) || '0',
},
create: {
name: branchName,
deploys: {
create: {
deployId,
url,
status,
},
},
},
update: {
deploys: {
upsert: {
where: {
deployId,
},
create: {
deployId,
url,
status,
},
update: {
url,
status,
},
},
},
},
},
},
},
})
return ctx.db.deploy({ deployId })
},
}
But it works for me locally, and I’m not even calling it in my function that returns the timeout.
Locally running netlify-lambda serve
with this code tells me the functions run within a few 100ms. I’ve tried putting a few console.logs in the first file but I’m not getting any of those in the Netlify admin logs.
Let me know if you need more! Thanks.