-
Notifications
You must be signed in to change notification settings - Fork 190
Add GraphQL API for managing rooms #399
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
Merged
Merged
Changes from 38 commits
Commits
Show all changes
140 commits
Select commit
Hold shift + click to select a range
98ed136
GraphQL API WIP
robertlong 55b1260
Fix formatting and remove inspect
robertlong bd512d5
Use a changeset error handling middleware
robertlong 3da617c
Add pagination to public rooms query
robertlong d396147
Add myRooms and authenticated routes
robertlong 8ea148a
Add favorite rooms query
robertlong c28f8fb
Add more room and scene fields
robertlong 6e718e1
Use dataloader for batch fetching scenes
robertlong b269d9b
Fix typo in comment
johnshaughnessy ada6276
specify preferred json codec
johnshaughnessy bdc1f8d
Add test cases for room query
johnshaughnessy 125769c
DRY up tests
johnshaughnessy 6883a09
Remove unused "variables" from tests
johnshaughnessy 1a5853f
DRY : add assign_creator function
johnshaughnessy b585a8c
Rename put_auth_header_for_email
johnshaughnessy 002f1e9
DRY: put_auth_header_for_account
johnshaughnessy 66d8c4a
DRY: graphql query
johnshaughnessy b7c55e5
Don't need to hit the iql api
johnshaughnessy 96d27c8
Test room creation. Add default creator assignment
johnshaughnessy 6b4c0b6
Specify json_codec
johnshaughnessy fec3753
Add room name to mutation result
johnshaughnessy 012d040
Test pagination
johnshaughnessy 0e3f85e
Fix warnings
johnshaughnessy 8f2611c
Formatting
johnshaughnessy e60ddff
Add mutation for updating room name
johnshaughnessy 2f4c8bb
Add capabilities to room resolver
johnshaughnessy ee0a66c
Refactor for readability
johnshaughnessy 4afe9d6
Broadcast changes to anyone connected to the hub channel
johnshaughnessy 5a81895
Add ability to update member_permissions
johnshaughnessy 81726e7
Remove unused vars
johnshaughnessy 15d6475
Add some documentation for the API
johnshaughnessy c5e89eb
Fixup doc
johnshaughnessy 5dc75b3
Add ability to modify allow_promotion
johnshaughnessy 57a052f
Add descriptions to graphql objects/fields
johnshaughnessy 20328ed
Add descriptions to scene types
johnshaughnessy 67dd3c0
Match on Repo.update errors
johnshaughnessy 342c165
Make specifying a room name optional. Add other fields
johnshaughnessy 1b06615
Authorization is enforced on a per-resolver basis
johnshaughnessy 568548f
Fix failing test case for allow_promotion
johnshaughnessy f8f8477
Add helper script for setting Authorization header
johnshaughnessy dcc8672
Remove duplicate field
johnshaughnessy 634f0f4
Setup guardian_db and ApiTokens
johnshaughnessy 6de2ca2
Show that revoked token cannot be verified in test
johnshaughnessy 8c0e869
Confer permissions onto api tokens
johnshaughnessy c8ac232
Remove hub_refresh_by_api
johnshaughnessy 3841cbb
Add primitive timing info as middleware
johnshaughnessy 01a6331
Build up middleware incrementally
johnshaughnessy 5a47417
Merge remote-tracking branch 'origin/feature/api-tokens' into feature…
johnshaughnessy 18b4b62
Verify the permissions on graphql api usage
johnshaughnessy 02c76c3
Start handling auth_errors in the plug
johnshaughnessy 028c3ae
Update guardian so we can avoid halt on error
johnshaughnessy 693204d
Add guardian_phoenix after guardian upgrade
johnshaughnessy 1d9fedd
Fix tests. Check for token in middleware.
johnshaughnessy 5f03033
Tighten up error handling / reporting
johnshaughnessy 5aa730c
Add TODO's from talking with Dom
johnshaughnessy 61e097d
Rename return_error -> put_error_result
johnshaughnessy 81c84e8
Rename Context -> AddAbsintheContext
johnshaughnessy 5c6b08c
Rename context.ex -> add_absinthe_context.ex
johnshaughnessy d9caf59
Remove unused middleware. Rename PutErrorResult
johnshaughnessy 85301be
Add mix task for generating api tokens
johnshaughnessy edb17af
Remove unused middleware
johnshaughnessy b7eabe2
Implement scopes and app_tokens
johnshaughnessy 6db7fcf
Modify helper mix task for generating tokens
johnshaughnessy f365bca
Remove insert auth header helper
johnshaughnessy e699e8b
Minor changes
johnshaughnessy f96f226
Remove unnecessary middleware
johnshaughnessy 69902c7
Rename Ret.ApiToken -> Ret.Api.Token
johnshaughnessy f652f0c
Update room access pattern for user and app tokens
johnshaughnessy 9a5c089
Fix tests and warnings
johnshaughnessy dc45130
Generate random room names
johnshaughnessy 5084f61
Reimplement create and update room with auth
johnshaughnessy 05d8008
Add some notes for graphiql testing
johnshaughnessy a279ce5
Remove unused middleware
johnshaughnessy b9a7175
Remove commented code
johnshaughnessy 82108fd
Remove unused permissions
johnshaughnessy a386b8f
Remove IO.inspect
johnshaughnessy b876e86
Fix warnings
johnshaughnessy 1de05d7
Implement can? for :reticulum_app_token
johnshaughnessy e2eec9b
Put generated token onto clipboard
johnshaughnessy 6f5a4e6
Check permissions for getting public rooms
johnshaughnessy f121458
Remove unused function
johnshaughnessy 2eb4934
Remove unused function
johnshaughnessy 497d97c
Remove outdated tests
johnshaughnessy 550863c
Add comments
johnshaughnessy 7f1c1cb
Lengthen ttl
johnshaughnessy 9f23b27
Create API token module. Replace jwt's in API
johnshaughnessy dfaf3f8
Remove guardian db
johnshaughnessy 884893b
Remove unused secrets
johnshaughnessy 3040fb4
Remove unused function
johnshaughnessy 8dc209c
Removed unused alias/import
johnshaughnessy c88e0a0
(Re)Implement revoke for tokens
johnshaughnessy 272003d
Fix introspection queries and invalid token errors
johnshaughnessy c5096c7
Check for introspection types how Absinthe does
johnshaughnessy 75a2087
Fix warnings
johnshaughnessy 6c22990
Remove TODO
johnshaughnessy d3bf787
Fix tests
johnshaughnessy 300bf33
Add sample graphiql workspace
johnshaughnessy a32f840
Format
johnshaughnessy 6f810a4
Update API Guide
johnshaughnessy 8a2e6f4
Remove graphiql notes
johnshaughnessy 737b716
Update scopes table in guide
johnshaughnessy 04ee343
Update formatting in guide
johnshaughnessy 8d0d6df
Update justification in guide table
johnshaughnessy 560da97
Remove unused error message
johnshaughnessy 275cfde
Move dataloader config
johnshaughnessy 617a3bf
Change title of guide
johnshaughnessy 59153bf
Do not assume xclip exists
johnshaughnessy 0df81f4
Check write_rooms scope to allow update_hub
johnshaughnessy c856764
Remove things from documentation that are not done
johnshaughnessy aa718ae
Check hub_bindings before allowed embeds
johnshaughnessy f8919ab
Remove API credentials expiration
johnshaughnessy a088b2f
Include rooms whose entry mode is invite
johnshaughnessy 8ef4ba1
Return more specific token error: :token_revoked
johnshaughnessy 6d19640
Return scene or scene_listing in room result
johnshaughnessy e7aa161
Add json scalar type for user_data
johnshaughnessy 6d1999b
Add missing close parenthesis
johnshaughnessy 465f637
Add indexes and prevent null in credentials table schema
johnshaughnessy 6afdb17
Fix query for favorite rooms
johnshaughnessy 0c9638f
Define internal functions with defp
johnshaughnessy 9009d96
Fix call to internal function
johnshaughnessy 4923a66
Remove max_page_size
johnshaughnessy 016d737
Fix credential changeset validation/constraints
johnshaughnessy 832898b
Do not have all tokens end in "09"
johnshaughnessy 50f7df6
Prefix the sid to the rest of the token
johnshaughnessy ec55da4
Update comment for Can impl for Atom
johnshaughnessy 0eabfb3
Add create_room function for api
johnshaughnessy 4d1d9c8
Fixup scene changes and member permissions
johnshaughnessy ec9cd68
Fix member perm parsing: return ArgumentError
johnshaughnessy 7059fdd
Remove unused test queries
johnshaughnessy 461de60
Update workspace
johnshaughnessy 4bdde03
PR feedback
johnshaughnessy 70bb8a5
Remove issued_at field
johnshaughnessy a02026d
Add (regular) API to manage (graphql) credentials
johnshaughnessy 2b633c1
Expand admin account permissions
johnshaughnessy e448b99
Remove create_accounts scope
johnshaughnessy 80c275d
Create test helper
johnshaughnessy 3b49320
PR Feedback
johnshaughnessy ca9ab00
Require a server-level flag for graphql api
johnshaughnessy d3adae7
lint
johnshaughnessy 2de8003
Merge pull request #436 from mozilla/feature/credentials-api
johnshaughnessy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| # Overview | ||
| Reticulum includes a [GraphQL](https://graphql.org/) API to better allow you to customize the app to your specific needs. | ||
|
|
||
| ## Accessing the API | ||
| The API can be accessed by sending `GET` or `POST` requests to `/api/v2/`. | ||
| Requests can be sent in code with an `HTTP` client library, on the command line with a tool like `curl`, with a GraphQL-specific client library, or any other tool that speaks `HTTP`. There is also an interactive GUI for accessing the API available at `/api/v2/graphiql`. | ||
|
|
||
| ## Authenticating requests | ||
| Most requests sent to the API need to be authenticated. To authenticate a request, add the http header `Authorization` with value `Bearer: <your API token>`. Currently, your API token is the same as your account token, which you can find with the following steps: | ||
| - Navigate to the homepage | ||
| - Sign in | ||
| - Open the developer console of your browser. ( | ||
| Instructions for opening the console in firefox: https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Opening_the_Web_Console | ||
| Instructions for chrome: https://developers.google.com/web/tools/chrome-devtools/open) | ||
| - Type `window.APP.store.state.credentials.token` into the console and press enter. | ||
| - Your token should be returned surrounded by quotations marks (`"<your API token here>"`) | ||
|
|
||
| It is likely that the authentication method will change in future releases of the API to include something like API tokens whose permissions can be limited to specific scopes, so that people are not encouraged to share admin account tokens. Sharing account tokens is dangerous - don't do it. | ||
|
|
||
| ## Passing arguments | ||
| We use a library called [`absinthe`](http://absinthe-graphql.org/) to power the `GraphQL` API. This library automatically converts between `camelCase` (a typical convention in `javascript`) and `snake_case` (a typical convention in `elixir`). For this reason, you will send and receive arguments and values in `camelCase`, but will see the corresponding values in `elixir` code as `snake_case`. | ||
|
|
||
| ## Rooms | ||
| The following examples show the capabilities of creating, querying, and modifying rooms. The code for these commands and object types can be found in [`/lib/ret_web/schema/room_types.ex`](../lib/ret_web/schema/room_types.ex) | ||
|
|
||
| ### Create a room | ||
| Request: | ||
| ``` | ||
| mutation { | ||
| createRoom(name:"My Fun Get-Together"){ | ||
| id | ||
| } | ||
| } | ||
| ``` | ||
| Response: | ||
| ```js | ||
| { | ||
| "data": { | ||
| "createRoom": { | ||
| "id": "3FqxixG" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Querying Rooms | ||
| Room queries return a `RoomList` object, which paginates responses. For a specific page or page size, pass the `page` or `pageSize` arguments along with the request. | ||
|
|
||
| #### My rooms | ||
| Request: | ||
| ``` | ||
| query { | ||
| myRooms(page: 1, pageSize: 10) { | ||
| entries { | ||
| name, | ||
| id, | ||
| scene { | ||
| ... on Scene { | ||
| id, | ||
| name | ||
| } | ||
| ... on SceneListing{ | ||
| id, | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| Response: | ||
| ```js | ||
| { | ||
| "data": { | ||
| "myRooms": { | ||
| "entries": [ | ||
| { | ||
| "id": "3FqxixG", | ||
| "name": "My Fun Get-Together", | ||
| "scene": null | ||
| }, | ||
| { | ||
| "id": "FmNKVjL", | ||
| "name": "Foo", | ||
| "scene": { | ||
| "id": "tXkCgJw", | ||
| "name": "Crater 2" | ||
| } | ||
| }, | ||
| "scene": { | ||
| "id": "74VD2Et", | ||
| "name": "Crater" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Query my favorite rooms | ||
| Request: | ||
| ``` | ||
| query { | ||
| myFavorites { | ||
| entries { | ||
| name, | ||
| id | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| Response: | ||
| ```js | ||
| { | ||
| "data": { | ||
| "favoriteRooms": { | ||
| "entries": [ | ||
| { | ||
| "id": "4jByd2w", | ||
| "name": "Uniform Ready Social" | ||
| }, | ||
| { | ||
| "id": "5wQhhbG", | ||
| "name": "Angelic Vibrant Spot" | ||
| }, | ||
| { | ||
| "id": "RmNv2k2", | ||
| "name": "Golden Perfect Volume" | ||
| }, | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| #### Query public rooms | ||
| Request: | ||
| ``` | ||
| query { | ||
| publicRooms { | ||
| entries { | ||
| name, | ||
| id | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| Response: | ||
| ```js | ||
| { | ||
| "data": { | ||
| "publicRooms": { | ||
| "entries": [ | ||
| { | ||
| "id": "z7LQiNi", | ||
| "name": "Big Time Room" | ||
| }, | ||
| { | ||
| "id": "SVnhCWq", | ||
| "name": "sdafasdf" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Updating rooms | ||
| #### Set room properties like `name`, `description`, and `roomSize` | ||
| ``` | ||
| mutation { | ||
| updateRoom( | ||
| id:"FmNKVjL", | ||
| name:"Foo bar baz", | ||
| description:"Some description", | ||
| roomSize:15, | ||
| ) { | ||
| id | ||
| } | ||
| } | ||
| ``` | ||
| #### Change the scene of a given room: | ||
| ``` | ||
| mutation { | ||
| updateRoom( | ||
| id:"FmNKVjL", | ||
| sceneId: "74VD2Et", | ||
| ) { | ||
| id | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Change member permissions in the room: | ||
| ``` | ||
| mutation { | ||
| updateRoom( | ||
| id:"FmNKVjL", | ||
| memberPermissions: { | ||
| fly: true, | ||
| spawnEmoji: true, | ||
| spawnDrawing: true, | ||
| pinObjects: false, | ||
| spawnCamera: false, | ||
| spawnAndMoveMedia: true | ||
| } | ||
| ) { | ||
| id | ||
| } | ||
| } | ||
| ``` | ||
| ### Change everything all in one go: | ||
|
|
||
| ``` | ||
| mutation { | ||
| updateRoom( | ||
| id:"FmNKVjL", | ||
| name:"Foo bar baz", | ||
| description:"Some description", | ||
| roomSize:15, | ||
| sceneId: "74VD2Et", | ||
| memberPermissions: { | ||
| fly: true, | ||
| spawnEmoji: true, | ||
| spawnDrawing: true, | ||
| pinObjects: false, | ||
| spawnCamera: false, | ||
| spawnAndMoveMedia: true | ||
| } | ||
| ) { | ||
| id | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.