Hi. A quick one hopefully. But I'm stuck on it :) ...
# sst
r
Hi. A quick one hopefully. But I'm stuck on it :) I'm setting up an ApolloApi in a typescript sst project. I want to import typeDefs from a *.graphql file and pass it in when the server is created. Usually I'd set up the webpack loader from the graphql-tag library for this and it would do the required transforms, but I can't figure out where to set up the webpack loader. Has anyone got this working?
t
I'm using gql codegen for this
Are you using that already?
r
I'm using codegen yes. But I wanted to do something like
Copy code
import typeDefs from './schema.graphql';

...

const server = new ApolloServer({
  typeDefs,
  resolvers
});
in the Apollo Server lambda. I discovered where to add esbuild plugins in an
esbuild.js
file, and ended up adding this one https://github.com/luckycatfactory/esbuild-graphql-loader Can't figure out how to get it to import though 😕
Copy code
const graphqlLoaderPlugin = require('@luckycatfactory/esbuild-graphql-loader');

module.exports = {
  plugins: [
    graphqlLoaderPlugin(),
  ]
};
I get this error
Error Transpiling Lambda code... TypeError: graphqlLoaderPlugin is not a function
Oh, I fixed it by changing it to
graphqlLoaderPlugin.default()
t
I actually wrote a tiny little file that generates the typedefs from .graphql file
It's weird it's not built into graphql-codegen, they asked for a PR with it thoguh
r
Yeah, it would be handy. I think it's just always been handled with a loader.