Hey! I'm trying to support importing .graphql file...
# help
c
Hey! I'm trying to support importing .graphql files, but there's nothing about this in the docs and also I can't find how I would add loaders for this myself. Any suggestions on how to deal with this? I'm aware that I can simply use gql as string in javascript, but I'm using a GUI to create the schema which is then copy pasted into my project so that removes that option.
d
Could you clarify where you’re trying to use the graphql. Do you mean you’re trying to import a schema into a stack construct, or trying to use graphql operations in your application code?
c
I'm trying to import a graphql file which I then import into my Apollo Server constructor as typeDefs
(Sorry alread away from laptop. Will send code example tomorrow. I'm just using the default ApolloApi construct
Tx for your reply btw!
f
@Dan Greaves Thanks for helping with the triage 💪
@Chris Visser, it seems using the loader can help. Give this a try:
Copy code
new ApolloApi(this, "MyApi", {
  defaultFunctionProps: {
    bundle: {
      loader: {
        ".gql": "text"
      },
    },
  },
});
And in ur Lambda code, you can
import
the file
c
Omg this is.... NICE 🙂 It wasnt clear to me from the docs. If this works I will be happy and expect a PR on the docs :')
@Frank Fyi it works! I've just had to ignore the typescript error:
Copy code
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as schema  from './schema.gql';
f
Ah ic. You could also do this:
Copy code
new ApolloApi(this, "MyApi", {
  defaultFunctionProps: {
    bundle: {
      copyFiles: [{ from: "path/to/schema.gql", to: "path/to/schema.gql" }],
    },
  },
});
This way, you don’t have to
import
the file. You can use
fs.readFile
.
c
Ah cool. Yes was trying this one. But indeed it requires me to bundle it along with the app, because the gql file would not exist xD