Hi Guys, I’m trying to add a lambda authorizer to ...
# help
c
Hi Guys, I’m trying to add a lambda authorizer to the GraphQLApi constructor. The doc says that GraphQLApi extends Api so it should be possible to add the “authorizers” key (that is also suggested by typescript) but when I try to define it I get the following error
"Type '{ myAuthorizer: { type: string; function: sst.Function; resultsCacheTtl: string; }; }' is not assignable to type 'undefined'.
here you have the code:
Copy code
const api = new sst.GraphQLApi(this, "apollo-api", {
      server: fun,
      authorizers: {
        myAuthorizer: {
          type: "lambda",
          function: new sst.Function(this, "Authorizer", {
            handler: "src/authorizer.main",
          }),
          resultsCacheTtl: "30 seconds",
        },
      }
    });
f
Hey @Ciak, I’m not able to reproduce this on my end.. here’s what I tried
Copy code
const api = new sst.GraphQLApi(stack, "Api", {
    authorizers: {
      myAuthorizer: {
        type: "lambda",
        function: new sst.Function(stack, "Authorizer", {
          handler: "src/lambda.main"
        }),
        resultsCacheTtl: "30 seconds",
      }
    },
    defaults: {
      authorizer: "myAuthorizer"
    },
    server: "src/apollo/graphql.handler",
  });
Very similar to what u had.
Btw, are you seeing the error in the editor?
c
Yes, I’ve tried with 2 different editor, mine and my coworker’s and we get the same error. I’m running sst v 1.0 ..