I’m having an issue where I created an AppSyncApi ...
# help
g
I’m having an issue where I created an AppSyncApi in one project, and am trying to extend it in another project (ie, add resolvers) by importing the GraphQL like the example:
Copy code
import { GraphqlApi } from "@aws-cdk/aws-appsync-alpha";

const api = new AppSyncApi(this, "GraphqlApi", {
  graphqlApi: GraphqlApi.fromGraphqlApiAttributes(this, "IGraphqlApi", {
    graphqlApiId,
  }),
});
However, if i then try to add a unit resolver where i reference a datasource I added in the first stack it fails; also, if i try to lookup the datasource by name
Copy code
api.getDataSource('mydsName');
it also returns undefined. Any thoughts?
t
Hm @Frank do we support importing like this?
d
I think it should be this, if it behaves like CDK:
Copy code
const api =  GraphqlApi.fromGraphqlApiAttributes(this, "IGraphqlApi", {
    graphqlApiId,
  });
g
That's not the problem. The problem is getting access to the data source which is needed when you add a resolver.
t
Yeah the issue is when you import it we don't know anything about sst specific concepts so we're not hydrating those fields. Idk if this is supported right now
g
I don't know if it's even possible in CDK. It's like you can only add the resolvers in the same context as where you add the data source.
t
You can add resolvers lazily but it needs to be within the same project
The issue is there some state that exists in the project that you defined it that is lost when you import it
f
Sorry for the late follow up guys. @Guy Shechter just to clarify, the data source
mydsName
is not created in this
AppSyncApi
construct right?
hmm… I was thinking when u import the
graphqlApi
, we can make the construct also allow u to import some data sources… but then I don’t think CDK allows u to import data sources 🤔
ie. the DynamoDbDataSource doesn’t have an import method https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-appsync.DynamoDbDataSource.html
g
That's what I was hoping yes. It's attached in a different construct.
f
Is that construct in the same SST app?
g
No
f
I see. Yeah there doesn’t seem to be an easy to import existing data sources.