-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(appsync): implement resolvable fields for code-first schema #9660
Conversation
@andrestone @asterikx would love your thoughts on the api! The README can be found here. The I made an reference app for the Star Wars API here that you can check out to see a big example of dynamic schema generation. We are planning to implement a |
Are we missing Update / other thing(s):
|
Yes! Will add this in a PR next week along with
I had an idea for another PR but to make the |
Sounds great, feels more like CDK. |
@andrestone does the api feel natural? Like declaring types, fields and linking resolvers inline |
I think it's a good lower level abstraction. I guess the important thing here is to create a solid base for L2/L3 constructs that will deliver less generic but more fluid experiences depending on developer preferences. I couldn't play around much today, though. I'll certainly do it over the weekend. |
Sweet! Yeah next week I plan to add functions like Hopefully, this will make the experience a lot more fluid! |
Nice. There's one thing that I think could be done better or maybe better documented. Since this is mostly a "helper" API, something that will support the development of a "backend" logic instead of infrastructure deployment per se, it would be good to have better defined flows for those two contexts. For example, during the code-first schema definition "flow", when using most of the helper classes / functions, it makes sense that it all happens out of the "construct programming model" context. So, no need to reference the scope, since we would be outside of the tree. And it's pretty much like that already, with the exception of when you need to create a So the suggestion would be to expose an API in |
@andrestone thats a great suggestion! Yeah I think this parallels a lot of what the intention of the code-first approach. Allowing declaration to happen externally allows for dynamic declaration. Originally, the idea was that users would declare their resolvable fields in construction. So you would create your data sources and what not, and then pass it in (like what I do here in the SWAPI demo). My only concern is that I don't want people to think they can declare resolvers on interfaces (which only allows for |
How about a method from an abstract class that manages the attachment of the resolvers? Or (even better?) a |
At the end of the day, if someone were to try to add a data source to an interface, it still wouldn't create a resolver because the generating function only exists in
Im not sure what this means.. I think what we could end up doing, is just add a function to ResolverOptions {
readonly pipelineConfig?: string[];
readonly requestMappingTemplate?: MappingTemplate;
readonly responseMappingTemplate?: MappingTemplate;
}
export class ObjectType extends InterfaceType {
constructor(name: string, props: ObjectTypeProps) {
...
}
public attachResolverToField(fieldName: string, dataSource: BaseDataSource, options: ResolverOptions) {
// This would search your ObjectType for the field name and adjust the definition
}
} |
Nevermind the other ideas, this snippet looks perfect. |
Hello! Could we expose |
Good point! I was going to add this once AppSync |
@andrestone added implementation for @shivlaks I separated the tests (only for code-first tests) so each one file has one describe :) felt like it would get hairy pretty soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Implemented interfaces and resolvable fields for code-first schema.
Field
extendsGraphqlType
and will allow you to define arguments.Field Example
The CDK code required would be:
ResolvableField
extendsField
and will allow you to define arguments and its resolvers.Object Types can have fields that resolve and perform operations on
your backend.
Resolvable Field Example
For example, if we want to create the following type:
The CDK code required would be: