Skip to content

Commit 440023c

Browse files
committed
added README
1 parent 6f0df86 commit 440023c

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Understanding GraphQL
2+
3+
**GraphQL** ( Graph Query Language ) is a query language for APIs and a server-side runtime for executing queries by using a type system you define for your data.
4+
5+
In REST APIs, there's clearly a defined structure of information returned from each endpoint (like to fetch posts endpoint would be like _http://some.api.com/posts_). GraphQL always exposes only one endpoint, allowing the client to decide what data it really needs from a predefined pattern.
6+
7+
## Query
8+
9+
Queries are used to make requests for data from the server. As seen in below example, the query has exactly the same shape as the result.
10+
11+
Example for query:
12+
13+
```
14+
{
15+
me {
16+
name
17+
}
18+
}
19+
20+
```
21+
22+
returns a JSON:
23+
24+
```
25+
{
26+
"me": {
27+
"name": "Morty"
28+
}
29+
}
30+
```
31+
32+
## Mutations
33+
34+
In GraphQL, Mutations are used to modify data on server. **mutation** is just a keyword.
35+
Technically any query could be implemented to update data. However, it's an established convention that any operations that causes writes should be sent explicitly via a mutation.
36+
37+
Mutations are really much like the query objects, they too have a type, arguments and a resolve function.
38+
39+
Just like in queries, if the mutation field returns an object type, nested fields can also be fetched.
40+
41+
example for mutation:
42+
43+
```
44+
mutation {
45+
addUser(firstName: "AB", age:23, companyId:"2") {
46+
id
47+
firstName
48+
company {
49+
name
50+
}
51+
}
52+
}
53+
```
54+
55+
_for more details_ checkout official docs at https://graphql.org/learn/

0 commit comments

Comments
 (0)