fly-apps / fly-laravel

Run your Laravel apps on Fly
42 stars 3 forks source link

Let users select their organization #29

Closed fideloper closed 1 year ago

fideloper commented 1 year ago

To get user's organizations, we can make a graphql call - just like getting the user's location.

A sticky point MIGHT be that we need the user's fly token. In theory this is in ~/.fly/config.yml, or via fly auth token.

Here's what the GraphQL call looks like tho:

curl \
    -H "Authorization: Bearer `fly auth token`" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" 
    https://api.fly.io/graphql \
    -d '{"query": "query {currentUser {email} organizations {nodes{id slug name type viewerRole}}}"}'

The response looks something like this:

{
  "data": {
    "currentUser": {
      "email": "fideloper@fly.io"
    },
    "organizations": {
      "nodes": [
        {
          "id": "xxxyyy",
          "slug": "personal",
          "name": "Chris Fidao",
          "type": "PERSONAL",
          "viewerRole": "admin"
        },
        {
          "id": "yyyxxx",
          "slug": "chipper-ci",
          "name": "Chipper CI",
          "type": "SHARED",
          "viewerRole": "admin"
        }
      ]
    }
  }
}