Skip to content

Setup Studio Account #133

Setup Studio Account

Setup Studio Account #133

name: Setup Studio Account
on:
workflow_run:
workflows: ["Initial Setup"]
types:
- completed
env:
GEN: ${{ secrets.GEN || 'ws1' }}
APOLLO_KEY: ${{ secrets.APOLLO_USER_KEY }}
jobs:
publish:
uses: ./.github/workflows/publish-subgraph.yml
secrets: inherit
pqs:
runs-on: ubuntu-latest
steps:
- name: Create PQ List
run: |
curl --request POST \
--header 'content-type: application/json' \
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
--url 'https://graphql.api.apollographql.com/api/graphql' \
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $description: String, $linkedVariants: [String!]) {\n graph(id: $graphId) {\n createPersistedQueryList(name: $name, description: $description, linkedVariants: $linkedVariants) {\n ... on CreatePersistedQueryListResult {\n persistedQueryList {\n id\n createdAt\n }\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"pq_list","description":"Our PQ List","linkedVariants":["current"]}}' -o pq.json
cat pq.json
- name: Set Env
run: echo "PQ_ID=$(cat pq.json | jq .data.graph.createPersistedQueryList.persistedQueryList.id)" >> $GITHUB_ENV
- name: Install Rover
run: |
curl -sSL https://rover.apollo.dev/nix/v0.19.0 | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Checkout
uses: actions/checkout@v3
- name: Publish PQ List
run: |
rover persisted-queries publish --graph-id ${{vars.ACTOR}}${{env.GEN}} --list-id ${{env.PQ_ID}} \
--manifest ./final/workshop-pq-manifest.json
deploy:
needs: publish
uses: ./.github/workflows/deploy-router.yml
secrets: inherit
install-url:
needs: deploy
runs-on: ubuntu-latest
steps:
- id: "auth"
uses: "google-github-actions/auth@v0"
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Get URL
run: |
gcloud run services describe ${{vars.ACTOR}}-router --region us-central1 --format 'value(status.url)' > url.json
echo "URL=$(cat url.json)" >> $GITHUB_ENV
- name: Set URL
run: |
curl --request POST \
--header 'content-type: application/json' \
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
--url 'https://graphql.api.apollographql.com/api/graphql' \
--data '{"query":"mutation UpdateURL($name: String!, $graphId: ID!, $url: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updateURL(url: $url) {\n createdAt\n }\n }\n }\n}","variables":{"name":"current","graphId":"${{vars.ACTOR}}${{ env.GEN }}","url":"${{ env.URL }}"}}'
- name: Set Subscription URL
run: |
curl --request POST \
--header 'content-type: application/json' \
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
--url 'https://graphql.api.apollographql.com/api/graphql' \
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $subscriptionUrl: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updateSubscriptionURL(subscriptionUrl: $subscriptionUrl) {\n createdAt\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"current","subscriptionUrl":"${{ env.URL }}"}}'
preflightScript:
needs: publish
runs-on: ubuntu-latest
steps:
- name: Create PreFlight Script
run: |
curl --request POST \
--header 'content-type: application/json' \
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
--url 'https://graphql.api.apollographql.com/api/graphql' \
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $preflightScript: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updatePreflightScript(preflightScript: $preflightScript) {\n createdAt\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"current","preflightScript":"console.log(\"fetching new token.....\");const getToken=async e=>{let o=await explorer.fetch(\"https:\/\/proxy-j3nprurqka-uc.a.run.app/authn\",{method:\"POST\",header:{\"Content-Type\":\"application\/json\"},body:JSON.stringify({email:e,password:\"apolloworkshop\",returnSecureToken:!0})});return o.json()},authorizedCredentials=await getToken(\"[email protected]\"),{idToken:authorizedToken}=authorizedCredentials;explorer.environment.set(\"authorizedToken\",authorizedToken),console.log(\"successfully set authorized token\");const unauthorizedCredentials=await getToken(\"[email protected]\"),{idToken:unauthorizedToken}=unauthorizedCredentials;explorer.environment.set(\"unauthorizedToken\",unauthorizedToken),console.log(\"successfully set token unauthorized token\");"}}'