|
| 1 | +--- |
| 2 | +title: "GraphQL querying support" |
| 3 | +weight: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +{{% notice info %}} |
| 7 | +<i class="fas fa-language"></i> Diese Seite wird von Englisch |
| 8 | +auf Deutsch übersetzt. Sprichst Du Deutsch? Hilf uns die Seite |
| 9 | +zu übersetzen indem Du uns einen Pull Reqeust schickst! |
| 10 | +{{% /notice %}} |
| 11 | + |
| 12 | +GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. It gives users the power to ask for exactly what they need and nothing more. |
| 13 | + |
| 14 | +## Enums |
| 15 | +Enums represent possible sets of values for a field. |
| 16 | + |
| 17 | +For example, the `Node` object has a field called `status`. The state is an enum (specifically, of type `Status`) because it may be `UP` , `DRAINING` or `UNAVAILABLE`. |
| 18 | + |
| 19 | +## Scalars |
| 20 | +Scalars are primitive values: `Int`, `Float`, `String`, `Boolean`, or `ID`. |
| 21 | + |
| 22 | +When calling the GraphQL API, you must specify nested subfield until you return only scalars. |
| 23 | + |
| 24 | + |
| 25 | +## Structure of the Schema |
| 26 | +The structure of grid schema is as follows: |
| 27 | + |
| 28 | +```shell |
| 29 | +{ |
| 30 | + grid: { |
| 31 | + uri, |
| 32 | + totalSlots, |
| 33 | + usedSlots, |
| 34 | + nodes : [ |
| 35 | + { |
| 36 | + id, |
| 37 | + uri, |
| 38 | + status, |
| 39 | + maxSession, |
| 40 | + capabilities |
| 41 | + } |
| 42 | + ] |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## Querying GraphQL |
| 48 | + |
| 49 | +The best way to query GraphQL is by using `curl` requests. GraphQL allows you to fetch only the data that you want, nothing more nothing less. |
| 50 | + |
| 51 | +Some of the example GraphQL queries are given below. You can build your own queries as you like. |
| 52 | + |
| 53 | +### Querying the number of `totalSlots` and `usedSlots` in the grid : |
| 54 | + |
| 55 | +```shell |
| 56 | +curl -X POST -H "Content-Type: application/json" --data 'query { grid { totalSlots, usedSlots } }' -s <LINK_TO_GRAPHQL_ENDPOINT> |
| 57 | +``` |
| 58 | + |
| 59 | +Generally on local machine the `<LINK_TO_GRAPHQL_ENDPOINT>` would be `http://localhost:4444/graphql` |
| 60 | + |
| 61 | +### Querying the capabilities of each node in the grid : |
| 62 | + |
| 63 | +```shell |
| 64 | +curl -X POST -H "Content-Type: application/json" --data 'query { grid { nodes { capabilities } } }' -s <LINK_TO_GRAPHQL_ENDPOINT> |
| 65 | +``` |
| 66 | + |
| 67 | +### Querying the status of each node in the grid : |
| 68 | + |
| 69 | +```shell |
| 70 | +curl -X POST -H "Content-Type: application/json" --data 'query { grid { nodes { status } } }' -s <LINK_TO_GRAPHQL_ENDPOINT> |
| 71 | +``` |
| 72 | + |
| 73 | +### Querying the URI of each node and the grid : |
| 74 | + |
| 75 | +```shell |
| 76 | +curl -X POST -H "Content-Type: application/json" --data 'query { grid { nodes { uri }, uri } }' -s <LINK_TO_GRAPHQL_ENDPOINT> |
| 77 | +``` |
0 commit comments