https://serverless-stack.com/ logo
#sst
Title
# sst
m

Mike McCall

04/01/2021, 4:59 AM
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

Jay

04/01/2021, 12:01 PM
I ran into this. It looks like the recent cdk version doesn’t expose the url anymore. Only the api Id.
m

Mike McCall

04/01/2021, 1:32 PM
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

Jay

04/01/2021, 1:39 PM
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

Mike McCall

04/01/2021, 1:42 PM
Sounds we are experiencing the same ts error.
j

Jay

04/01/2021, 2:14 PM
👍
f

Frank

04/01/2021, 5:05 PM
@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

Mike McCall

04/01/2021, 5:07 PM
ok, so you recommend creating the api with cdk construct and passing that in? Aren’t you casting this.appSyncApi as GraphqlApi?
f

Frank

04/01/2021, 5:07 PM
When you import like this,
appsync.GraphqlApi.fromGraphqlApiAttributes
returns an
IGraphqlApi
type.
m

Mike McCall

04/01/2021, 5:08 PM
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

Frank

04/01/2021, 5:13 PM
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

Mike McCall

04/01/2021, 5:19 PM
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

Frank

04/01/2021, 5:22 PM
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

Mike McCall

04/01/2021, 5:24 PM
Awesome.
f

Frank

04/01/2021, 7:11 PM
Aight v0.10.7 it is
2 Views