Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b2adcd

Browse files
webinistaAisha Blake
authored and
Aisha Blake
committed
Docs: Encyclopedia entry for GraphQL (gatsbyjs#20105)
* GraphQL intro. * GraphQL outline. * docs/glossary: GraphQL entry. * Add a glossary link for the GraphQL entry. * Add a sentence that explains the code block that follows. * Convert tabs in code blocks to spaces. * Add a missing comma to JSON code sample. * Change first heading to h2 * Update relative URLs
1 parent 4134f44 commit 2b2adcd

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

docs/docs/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ The [public-facing](#public) interface for your website or app, delivered using
140140

141141
Gatsby is a modern website framework that builds performance into every website or app by leveraging the latest web technologies such as [React](#react), [GraphQL](#graphql), and modern [JavaScript](#javascript). Gatsby makes it easy to create blazing fast, compelling web experiences without needing to become a performance expert.
142142

143-
### GraphQL
143+
### [GraphQL](/docs/glossary/graphql)
144144

145145
A [query](#query) language that allows you to pull data into your website or app. It’s the [interface that Gatsby uses](/docs/graphql/) for managing site data.
146146

docs/docs/glossary/graphql.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: GraphQL
3+
disableTableOfContents: true
4+
---
5+
6+
## What is GraphQL?
7+
8+
GraphQL is a query language for requesting information from an [API](/docs/glossary#api), and a protocol for servers that support it. GraphQL is one of the ways that you can import data into your Gatsby components.
9+
10+
Facebook created GraphQL in 2012 when it realized that it needed an API capable of supporting both web-based and native mobile applications. Facebook released GraphQL with an open source license in 2015.
11+
12+
More traditional APIs use a separate endpoint for each piece or type of data you'd like to request. For example, a newspaper API might contain:
13+
14+
- an `/articles/<id>` endpoint that returns a specific news story;
15+
- a `/reporters/<id>` endpoint that returns information about a particular reporter.
16+
17+
A single news article page might require two separate network requests: one to retrieve the story data, and another for the reporter's contact details. What's more, the `/reporters` endpoint may return more data than you want to display; it might return their biography and social media accounts, when their name, email, and photo are all that you need for the page.
18+
19+
A GraphQL API, on the other hand, has a single endpoint. To retrieve data, you send one request string that uses a GraphQL-specific syntax. GraphQL executes the functions necessary to retrieve the data that you've requested, and returns a single JSON response.
20+
21+
A request for an article and its reporter might look like the example that follows.
22+
23+
```graphql
24+
{
25+
article(id: '7fdc2787469b') {
26+
title
27+
body
28+
reporter(id: '64669b3f') {
29+
name
30+
email
31+
photo
32+
}
33+
}
34+
}
35+
```
36+
37+
And its response contains only what you've requested.
38+
39+
```json
40+
{
41+
"data": {
42+
"article": {
43+
"title": "Gatsby promotes GraphQL adoption",
44+
"body": "...",
45+
"reporter": {
46+
"name": "Jane Gatsby",
47+
"email": "[email protected]",
48+
"photo": "images/reporters/janegatsby.jpg"
49+
}
50+
}
51+
}
52+
}
53+
```
54+
55+
You do not have to use GraphQL with Gatsby, however GraphQL offers a few advantages over other methods of importing data.
56+
57+
- You can retrieve only the data that you need for a view.
58+
- You can add new data types and capabilities without needing to create a new endpoint.
59+
- You can store content in whatever way makes sense for your site, whether that's in a database, a third-party headless CMS, or Markdown-formatted text files.
60+
61+
## Learn more
62+
63+
- [GraphQL & Gatsby](/docs/graphql/)
64+
65+
- [Why Gatsby Uses GraphQL](/docs/why-gatsby-uses-graphql/)
66+
67+
- [GraphQL](https://graphql.org) official site
68+
69+
- [How to GraphQL](https://www.howtographql.com/)

www/src/data/sidebars/doc-links.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@
698698
- title: Glossary
699699
link: /docs/glossary/
700700
items:
701+
- title: GraphQL
702+
link: /docs/glossary/graphql
701703
- title: Node.js
702704
link: /docs/glossary/node
703705
- title: React

0 commit comments

Comments
 (0)