Does AppSync support resolver level auth? I'm usin...
# help
a
Does AppSync support resolver level auth? I'm using Auth0 and the SST docs show route level
authorisationType
, but I can't see it mentioned for AppSync.
I've just seen this (👇 ) Not sure if this is the only way though. I'd love to be able to do it in config
f
Hey @Alex Price, I’m looking at the CDK doc for AppSync, it seems like you can use directives in code https://docs.aws.amazon.com/cdk/api/latest/docs/aws-appsync-readme.html#directives
a
Ooh exciting! Thanks Frank
Do you know where they are placed?
f
I’m not too sure. Maybe see if you can find a CDK example with it. That should also work for SST 🤔
a
Awesome thanks 🙏
f
Np, let me know what you find!
a
Looks like it's inside of
ResolvableField
which I assume has been abstracted away by SST 😕 (edit: can't find
ResolvableField
in SST codebase)
(though this is part of an issue, so might not be 100% correct)
f
Hey Alex, it seems you can do this using the Code-First approach when defining the schema. I put together some code based on the example above:
Copy code
import * as appsync from "@aws-cdk/aws-appsync";

// Creates AppSync API
const api = new sst.AppSyncApi(this, "GraphqlApi", {
  dataSources: {
    mainDS: "src/notes.main",
  },
});

// Add a resolvable field
api.graphqlApi.addMutation('setStatus', new appsync.ResolvableField({
  returnType: appsync.GraphqlType.string(),
  args: {
    id: appsync.GraphqlType.string(),
  },
  dataSource: api.getDataSource("mainDS"),
  directives: [
    appsync.Directive.cognito()
  ]
}));
So you use
sst.AppSyncApi
to create the dataSources first. And then add the resolvable field.
^I haven’t tried the code above, you might need to tweak the returnType and args based on ur setup.
Give it a try and let me know if it works for you!