Skip to content

Commit 8a2d96e

Browse files
committed
add learn introduction page
1 parent bea4df0 commit 8a2d96e

File tree

5 files changed

+96
-79
lines changed

5 files changed

+96
-79
lines changed

site/learn/BestPractice-Authorization.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ title: Authorization
33
layout: ../_core/DocsLayout
44
category: Best Practices
55
permalink: /learn/authorization/
6-
next: /learn/serving-over-http/
76
---
87

98
> Delegate authorization logic to the business logic layer

site/learn/BestPractice-ServingOverHTTP.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ title: Serving over HTTP
33
layout: ../_core/DocsLayout
44
category: Best Practices
55
permalink: /learn/serving-over-http/
6+
next: /learn/authorization/
67
---
78

89
HTTP is the most common choice for client-server protocol when using GraphQL because of its ubiquity. Here are some guidelines for setting up a GraphQL server to operate over HTTP.
910

10-
### Web Request Pipeline
11+
## Web Request Pipeline
1112
Most modern web frameworks use a pipeline model where requests are passed through a stack of middleware (AKA filters/plugins). As the request flows through the pipeline, it can be inspected, transformed, modified, or terminated with a response. GraphQL should be placed after all authentication middleware, so that you have access to the same session and user information you would in your HTTP endpoint handlers.
1213

13-
### URIs, Routes
14+
## URIs, Routes
1415
HTTP is commonly associated with REST, which uses "resources" as its core concept. In contrast, GraphQL's conceptual model is an entity graph. As a result, entities in GraphQL are not identified by URLs. Instead, a GraphQL server operates on a single URL/endpoint, usually `/graphql`, and all GraphQL requests for a given service should be directed at this endpoint.
1516

16-
### HTTP Methods, Headers, and Body
17+
## HTTP Methods, Headers, and Body
1718
Your GraphQL HTTP server should handle the HTTP GET and POST methods.
1819

19-
#### GET request
20+
### GET request
2021

2122
When receiving an HTTP GET request, the GraphQL query should be specified in the "query" query string. For example, if we wanted to execute the following GraphQL query:
2223

@@ -36,15 +37,15 @@ http://myapi/graphql?query={me{name}}
3637

3738
Query variables can be sent as a JSON-encoded string in an additional query parameter called `variables`. If the query contains several named operations, an `operationName` query parameter can be used to control which one should be executed.
3839

39-
#### POST request
40+
### POST request
4041

4142
A standard GraphQL POST request should use the `application/json` content type, and include a JSON-encoded body of the following form:
4243

4344
```js
4445
{
4546
"query": "...",
4647
"operationName": "...",
47-
"variables": { variable1: value, ... }
48+
"variables": { variable1: value, ... }
4849
}
4950
```
5051

@@ -57,7 +58,7 @@ In addition to the above, we recommend supporting two additional cases:
5758

5859
If you're using express-graphql, you already get these behaviors for free.
5960

60-
### Response
61+
## Response
6162

6263
Regardless of the method by which the query and variables were sent, the response should be returned in the body of the request in JSON format. As mentioned in the spec, a query might result in some data and some errors, and those should be returned in a JSON object of the form:
6364

@@ -70,7 +71,7 @@ Regardless of the method by which the query and variables were sent, the respons
7071

7172
If there were no errors returned, the `"errors"` field should not be present on the response. If no data is returned, [according to the GraphQL spec](http://facebook.github.io/graphql/#sec-Data), the `"data"` field should only be included if the error occurred during execution.
7273

73-
### GraphiQL
74+
## GraphiQL
7475
GraphiQL is useful during testing and development but should be disabled in production by default. If you are using express-graphql, you can toggle it based on the NODE_ENV environment variable:
7576

7677
```
@@ -80,5 +81,5 @@ app.use('/graphql', graphqlHTTP({
8081
}));
8182
```
8283

83-
### Node
84+
## Node
8485
If you are using NodeJS, we recommend using either [express-graphql](https://github.com/graphql/express-graphql) or [apollo-server](https://github.com/apollostack/apollo-server).

site/learn/BestPractice-ThinkingInGraphs.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ title: Thinking in Graphs
33
layout: ../_core/DocsLayout
44
category: Best Practices
55
permalink: /learn/thinking-in-graphs/
6-
next: /learn/authorization/
6+
next: /learn/serving-over-http/
77
---
88

9-
### It's Graphs All the Way Down [\*](https://en.wikipedia.org/wiki/Turtles_all_the_way_down)
9+
## It's Graphs All the Way Down [\*](https://en.wikipedia.org/wiki/Turtles_all_the_way_down)
1010
> With GraphQL, you model your business domain as a graph
1111
1212
Graphs are powerful tools for modeling many real-world phenomena because they resemble our natural mental models and verbal descriptions of the underlying process. With GraphQL, you model your business domain as a graph by defining a schema; within your schema, you define different types of nodes and how they connect/relate to one another. On the client, this creates a pattern similar to Object-Oriented Programming: types that reference other types. On the server, since GraphQL only defines the interface, you have the freedom to use it with any backend (new or legacy!).
1313

14-
### Shared Language
14+
## Shared Language
1515
> Naming things is a hard but important part of building intuitive APIs
1616
1717
Think of your GraphQL schema as an expressive shared language for your team and your users. To build a good schema, examine the everyday language you use to describe your business. For example, let's try to describe an email app in plain english:
@@ -50,7 +50,7 @@ fragment previewInfo on Email {
5050
}
5151
```
5252

53-
### Business Logic Layer
53+
## Business Logic Layer
5454
> Your business logic layer should act as the single source of truth for enforcing business domain rules
5555
5656
Where should you define the actual business logic? Where should you perform validation and authorization checks? The answer: inside a dedicated business logic layer. Your business logic layer should act as the single source of truth for enforcing business domain rules.
@@ -66,7 +66,7 @@ Sometimes, you will find yourself working with legacy data sources that do not p
6666

6767
Build your GraphQL schema to express "what" rather than "how". Then you can improve your implementation details without breaking the interface with older clients.
6868

69-
### One Step at a time
69+
## One Step at a time
7070
> Get validation and feedback more frequently
7171
7272
Don't try to model your entire business domain in one sitting. Rather, build only the part of the schema that you need for one scenario at a time. By gradually expanding the schema, you will get validation and feedback more frequently to steer you toward building the right solution.

site/learn/Introduction.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Introduction
3+
layout: ../_core/DocsLayout
4+
category: Learn
5+
permalink: /learn/
6+
next: /learn/queries/
7+
---
8+
9+
GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.
10+
11+
A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type. For example, a GraphQL service that tells us who the logged in user is (`me`) as well as that User's name might look something like this:
12+
13+
```graphql
14+
type Query {
15+
me: User
16+
}
17+
18+
type User {
19+
id: ID
20+
name: String
21+
}
22+
```
23+
24+
Along with functions for each field on each type:
25+
26+
```js
27+
function Query_me(request) {
28+
return request.auth.user;
29+
}
30+
31+
function User_name(user) {
32+
return user.getName();
33+
}
34+
```
35+
36+
Once a GraphQL service is running (typically at a URL on a web service), it can be sent GraphQL queries to validate and execute. A received query is first checked to ensure it only refers to the types and fields defined, then runs the provided functions to produce a result.
37+
38+
For example the query:
39+
40+
```graphql
41+
{
42+
me {
43+
name
44+
}
45+
}
46+
```
47+
48+
Could produce the JSON result:
49+
50+
```json
51+
{
52+
"me": {
53+
"name": "Luke Skywalker"
54+
}
55+
}
56+
```
57+
58+
Learn more about GraphQL: the query language, type system, how the GraphQL service works, and best practices for using GraphQL:
59+
60+
## Core Concepts
61+
62+
Start here to get a solid understanding of GraphQL and how it works.
63+
64+
- [Query Language](/learn/queries/)
65+
- [Type System](/learn/schema/)
66+
- Validation
67+
- Execution
68+
- Introspection
69+
70+
## Best Practices
71+
72+
Ready to start using GraphQL? Follow these guidelines to get a better understanding of how to approach common topics.
73+
74+
- [Thinking in Graphs](/learn/thinking-in-graphs/)
75+
- [Serving Over HTTP](/learn/serving-over-http/)
76+
- [Authorization](/learn/authorization/)
77+
- Domain Modeling
78+
- Pagination
79+
- Versioning
80+
- Performance
81+
- Security

site/learn/index.html.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)