You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.9 KiB

4 years ago
## GraphQL
### Objectives
The objective of this project is to learn graphql query language by creating your own profile. It will be provided,\
by the platform, a graphql endpoint that is connected to the database. So you can query this endpoint to obtain the information you desire.\
**Note** that for security reasons some tables are private and some are public, you will only be provided with certain content.
Your profile must have at least:
- Basic user identification
- XP amount
- level
- grades
- skills
- statistics
### Instructions
> Here is a small introduction and advantages of graphQL, if you want to read more about graphQL you can visit there [site](https://graphql.org/)
GraphQL is a query language for any API endpoint and runtime. The syntax lets you specify what data you want to receive from that API.\
You must have in mind that this language is used for API endpoints and not database. Unlike SQL,\
graphql query does not go to your database directly but to your graphql API endpoint which can connect to a database or any other data source.
You are already familiar to REST, since REST is a robust methodology of creating APIs and not elastic/scalable.\
It can be at the same time painful, because it requires individual creation of each API, example: `v1/user/item/{id}`, `v1/post/item/{id}` and so on.
The main feature of graphql compared to REST is that it lets you ask for specific information. And even better then that is the nesting feature.
Lets take for instance the social network project, if the server had a Graphql API that was connected to the database we could query this API using graphql language:
```js
query {
user {
name
}
}
```
This simple query will return an array with the name of the users. Imagine if you wanted the `date_of_birth`,\
you could just add this attribute to the query, example:
```js
query {
user {
name
dateOfBirth
}
}
```
Example for the nesting fetching:
```js
query {
user(id: "13") {
name
dateOfBirth
followers {
id
name
}
}
}
```
For this example we ask for the users followers and request their names and ids.\
The examples above are simple examples, **note** that this query is require the introduction of variables(arguments)\
so it will return just one user, the user that as the id equal to `13`.
In graphql the usage of arguments can be specified in the schema of the API endpoint. Here is the *docs* for the graphql endpoint you are going to use, [Schema](https://01.alem.school/public/subjects/grapqhl)
<!-- EXPLAIN WHAT IS GOING TO HAPPEN -->
---
### Usage
> Here are the list of tables that you are available to query:
- **User table**:
| id | githubLogin |
| --- | ----------: |
| 1 | person1 |
| 2 | person2 |
| 3 | person3 |
- **Transactions table**:
| id | type | amount | userId | createdAt |
| --- | :--: | -----: | -----: | -------------------------------: |
| 1 | xp | 234 | 1 | 2019-03-14T12:02:23.168726+00:00 |
| 2 | xp | 1700 | 2 | 2019-03-14T12:02:23.168726+00:00 |
| 3 | xp | 175 | 3 | 2019-03-14T12:02:23.168726+00:00 |
- **Progress table**:
| id | userId | attrs | bestResultId | objectId |
| --- | :----: | -----------------------: | -----------: | -------: |
| 1 | 1 | `{"name": "memory", ...` | s | 198 |
| 2 | 2 | `{"name": "memory", ...` | s | 198 |
| 3 | 3 | `{"name": "memory", ...` | s | 198 |
- **Results table**:
| id | grade | progressId |
| --- | ----: | ---------: |
| 1 | 0 | 58 |
| 2 | 0 | 58 |
| 3 | 1 | 58 |
- **Object table**:
| id | grade | progressId |
| --- | ----: | ---------: |
| 1 | 0 | 58 |
| 2 | 0 | 58 |
| 3 | 1 | 58 |
This project will help you learn about:
- [Graphql](https://graphql.org/) language