sid88in / serverless-appsync-plugin

serverless plugin for appsync
MIT License
951 stars 189 forks source link

Schema stitching for microservices gateway purposes #448

Open shawnmclean opened 3 years ago

shawnmclean commented 3 years ago

I have 2 AppSync services. These are separate packages with their own serverless.yml. For eg. UserService and OrderService.

I'd like to put an AppSync service in front of these 2. So I'll now have 3 serverless packages, with the new one being the proxy service.

I have this method lined up:

In the proxy service, I copy and paste the schema from the child services. This is tedious. I also need to update the request templates every time the schema changes in the child.

Is there a mechanism to combine all child schemas in the parent and set up the request templates via script?

Is this design still sensible? How can I achieve just the appsync to appsync section easily?

image (https://aws.amazon.com/blogs/mobile/appsync-microservices/)

bboure commented 3 years ago

Hi @shawnmclean I believe what you are looking for is schema federation. unfortunately, this is not supported by AppSync.

This plugin do support schema stitching though and you should be able to auto-merge schemas using glob patterns or by listing all your graphql schema files under schema example:

custom:
  appsync:
    schema: schemas/*.graphql

or

custom:
  appsync:
    schema:
      - userService.graphql
      - orderService.graphql

if you are using a monorepo for all these services, this should be straightforward.

Regarding the request mappings, I am not sure what you meant. Do you also need to copy them? Do you have an example?

shawnmclean commented 2 years ago

Thank you @bboure

Request mappings: I'm referring to Mapping Templates, like what's seen here: https://github.com/theburningmonk/appsyncmasterclass-backend/tree/main/mapping-templates

After I have the schema merged, is there a way to tell appsync to proxy a group of them to the downstream service without having to define individual mapping templates?