Frank
GraphqlApi
construct and remove graphql
from the dependency right? (so we don’t get pooped again @Derek Kershner 🥲)thdxr
05/23/2022, 10:09 PMthdxr
05/23/2022, 10:10 PMthdxr
05/23/2022, 10:11 PMDerek Kershner
05/23/2022, 10:11 PMDerek Kershner
05/23/2022, 10:13 PMDerek Kershner
05/23/2022, 10:17 PM>=15
)thdxr
05/24/2022, 2:18 PMexport * from "./GraphQLConstruct"
export * from "./NonGraphQLConstruct"
And someone imports anything from the index file, all the imports from all files are evaluated (need to verify this but the errors people posted on the previous build suggests this is true)
So that means it'll try to evaluate
import graphql from "graphql"
in GraphQLConstruct
even if you just import NonGraphQLConstruct
This is generally fine because if it's truly an optional dependency you should be using a dynamic import
const graphql = await import("graphql)
I can't do this inside a construct because CDK is class based all construct code needs to be synchronous
I need to see if doing it outside the construct avoids the issue abovethdxr
05/24/2022, 2:19 PMimport NonGraphQLConstruct from "@serverless-stack/resources/NonGraphQLConstruct"
thdxr
05/24/2022, 2:54 PMthdxr
05/24/2022, 2:56 PMconst graphql = someCondition ? await import(...) : undefined
thdxr
05/24/2022, 3:03 PMimport { createRequire } from "module"
const require = createRequire(import.meta.url);
let hasGraphQL = false
try {
require.resolve("graphql");
hasGraphQL = true
} catch { }
const { print } = hasGraphQL && await import("graphql")
const { mergeTypeDefs } = hasGraphQL && await import("@graphql-tools/merge");
const { loadFilesSync } = hasGraphQL && await import("@graphql-tools/load-files");
thdxr
05/24/2022, 3:06 PMasync function weakImport(pkg) {
try {
return await import(pkg)
} catch {
return {}
}
}
const { print } = await weakImport("graphql")
const { mergeTypeDefs } = await weakImport("@graphql-tools/merge");
const { loadFilesSync } = await weakImport("@graphql-tools/load-files");
thdxr
05/24/2022, 3:07 PMthdxr
05/24/2022, 3:52 PMDerek Kershner
05/24/2022, 4:25 PMthdxr
05/24/2022, 4:26 PMthdxr
05/24/2022, 4:26 PMDerek Kershner
05/24/2022, 4:34 PMJarod Stewart
05/24/2022, 4:35 PMthdxr
05/24/2022, 4:40 PMthdxr
05/24/2022, 4:40 PMDerek Kershner
05/24/2022, 4:42 PM