Using the AppSyncApi construct, it does not appear...
# sst
m
Using the AppSyncApi construct, it does not appear the underlying GraphqlApi is available. Unless I am missing something there is no way to output its properties? I am trying to output graphql url and api key.
j
I ran into this. It looks like the recent cdk version doesn’t expose the url anymore. Only the api Id.
m
Are you sure? I can access the properties using the aws appsync construct. Also, not using the latest I am on 1.94.1. https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-appsync.GraphqlApi.html#properties
Copy code
const api = new appSync.GraphqlApi(this, 'Api', {name: "api"})
    
new cdk.CfnOutput(this, "GraphqlUrl", { 
  value: api.graphqlUrl
});
j
I was using TS and the error I got was that the
IGraphqlApi
doesn't support the
graphqlUrl
property https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-appsync.IGraphqlApi.html. I'm not sure if that's the same error you are getting.
Yeah I think that might be the issue.
@Frank take a look when you get a chance.
m
Sounds we are experiencing the same ts error.
j
👍
f
@Mike McCall The
AppSyncApi
can also take an existing
appsync.GraphqlApi
. ie.
Copy code
new AppSyncApi(this, "GraphqlApi", {
  graphqlApi: appsync.GraphqlApi.fromGraphqlApiAttributes(this, "IGraphqlApi", {
    graphqlApiId,
  }),
  resolvers: {
    "Query    listNotes": "src/list.main",
    "Mutation createNote": "src/create.main",
  },
});
m
ok, so you recommend creating the api with cdk construct and passing that in? Aren’t you casting this.appSyncApi as GraphqlApi?
f
When you import like this,
appsync.GraphqlApi.fromGraphqlApiAttributes
returns an
IGraphqlApi
type.
m
The problem is I can’t access properties that are part of GraphqlApi but not IGraphqlApi such as apiUrl.
new CfnOutput(this, 'AppSyncUrl', { value: this.appSyncApi.graphqlUrl })
for example this fails.
f
right.. so the problem is: • when ppl are not importing,
sst.AppSyncApi
is creating an
appsync.GraphqlApi
and you will get a
GraphqlApi
type back • when ppl are importing, the imported api is of type
appsync.IGraphqlApi
and you will get a
IGraphqlApi
type back Hence we are always casting the property to
IGraphqlApi
So there are 2 solutions:
• you can do
(this.appSyncApi as appsync.GraphqlApi).graphqlUrl
• we change the construct such that
this.appSyncApi
is only set when ppl are not importing, and it will be of type
appsync.GraphqlApi
. This way we don’t need to accomodate for the imported case.
Let me know if I’m explaining this well. 😂
m
the first option is fine with me, however, I do feel the behavior shouldn’t change between cdk and what sst appsync returns for the appsyncapi property
f
Yeah that makes sense. Importing an existing AppSyncApi is a rare use case. Let’s go with the latter solution.
Let me put in the change, cut a release.
m
Awesome.
f
Aight v0.10.7 it is