Exercise 2: Deploy a subgraph change (⏳ 10 min)
Goal: Deploy a subgraph schema change, then fix errors.
Add a new field to the subgraph
You can do this using your local code editor, or with the GitHub UI.
Open up the
products/products.yamlfile.Find the
Query.productConnector and itsselectionparameter. Edit the file to add a new selection calledcategory.products.yamltype Query {product(id: ID!): Product@connect(source: "ecomm"http: { GET: "/products/{$args.id}" }selection: "id name description category"entity: true)}If you've used Apollo Connectors before, you might know this change will result in an error... but let's see what happens if this change was allowed to go through.
Find the problem
In a terminal window, run the following command to explore the logs for the Apollo Operator:
kubectl -n apollo-operator logs deployment/apollo-operatorYou should see some composition errors. In production, this would be caught by standard alerting tools.
You can also check the logs through Argo CD.
Open up your graph in Studio.
Click on Launches and find the failed launch.
Click on View Build Errors to see the errors.
Fix the problem
Open up the
products/products.yamlfile again.Fix the error by adding a
categoryfield to theProducttype.products.yamltype Product @key(fields: "id") {id: ID!name: Stringdescription: Stringcategory: String}Commit your changes and push them to the
mainbranch.After a short delay, the Router will re-deploy. You may need to re-run the
port-forwardcommands again.kubectl -n apollo-operator port-forward service/router-retail 4000:80kubectl -n argocd port-forward service/argocd-server 8080:80Open up your graph in Studio and go to the Explorer page.
Run the query to see category data come back.
query {product(id: "1") {idnamedescriptioncategory}}