Skip to content

Commit 0cee184

Browse files
committed
Merge branch 'source' into migrate-foundation-website-content
2 parents 7d96753 + 01397b3 commit 0cee184

File tree

6 files changed

+201
-7
lines changed

6 files changed

+201
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ yarn-error.log
6868
.pnp.js
6969
# Yarn Integrity file
7070
.yarn-integrity
71+
72+
# Swap files
73+
*.swp
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Ferry
3+
description: Ferry is a simple, powerful GraphQL Client for Flutter and Dart.
4+
url: https://ferrygraphql.com/
5+
github: gql-dart/ferry
6+
---
7+
8+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
name: GraphQLMiddleware
3+
description: Split up your GraphQL resolvers in middleware functions.
4+
url: https://github.com/maticzav/graphql-middleware
5+
github: maticzav/graphql-middleware
6+
npm: "graphql-middleware"
7+
---
8+
9+
GraphQL Middleware is a schema wrapper which allows you to manage additional functionality across multiple resolvers efficiently.
10+
11+
## Features
12+
13+
💡 Easy to use: An intuitive, yet familiar API that you will pick up in a second.
14+
💪 Powerful: Allows complete control over your resolvers (Before, After).
15+
🌈 Compatible: Works with any GraphQL Schema.
16+
17+
## Example
18+
19+
```ts
20+
const { ApolloServer } = require('apollo-server')
21+
const { makeExecutableSchema } = require('@graphql-tools/schema')
22+
23+
const typeDefs = `
24+
type Query {
25+
hello(name: String): String
26+
bye(name: String): String
27+
}
28+
`
29+
const resolvers = {
30+
Query: {
31+
hello: (root, args, context, info) => {
32+
console.log(`3. resolver: hello`)
33+
return `Hello ${args.name ? args.name : 'world'}!`
34+
},
35+
bye: (root, args, context, info) => {
36+
console.log(`3. resolver: bye`)
37+
return `Bye ${args.name ? args.name : 'world'}!`
38+
},
39+
},
40+
}
41+
42+
const logInput = async (resolve, root, args, context, info) => {
43+
console.log(`1. logInput: ${JSON.stringify(args)}`)
44+
const result = await resolve(root, args, context, info)
45+
console.log(`5. logInput`)
46+
return result
47+
}
48+
49+
const logResult = async (resolve, root, args, context, info) => {
50+
console.log(`2. logResult`)
51+
const result = await resolve(root, args, context, info)
52+
console.log(`4. logResult: ${JSON.stringify(result)}`)
53+
return result
54+
}
55+
56+
const schema = makeExecutableSchema({ typeDefs, resolvers })
57+
58+
const schemaWithMiddleware = applyMiddleware(schema, logInput, logResult)
59+
60+
const server = new ApolloServer({
61+
schema: schemaWithMiddleware,
62+
})
63+
64+
await server.listen({ port: 8008 })
65+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: GraphQLShield
3+
description: A GraphQL tool to ease the creation of permission layer.
4+
url: https://github.com/maticzav/graphql-shield
5+
github: maticzav/graphql-shield
6+
npm: "graphql-shield"
7+
---
8+
9+
GraphQL Shield helps you create a permission layer for your application. Using an intuitive rule-API, you'll gain the power of the shield engine on every request and reduce the load time of every request with smart caching. This way you can make sure your application will remain quick, and no internal data will be exposed.
10+
11+
```ts
12+
import { rule, shield, and, or, not } from 'graphql-shield'
13+
14+
// Rules
15+
16+
const isAuthenticated = rule({ cache: 'contextual' })(
17+
async (parent, args, ctx, info) => {
18+
return ctx.user !== null
19+
},
20+
)
21+
22+
const isAdmin = rule({ cache: 'contextual' })(
23+
async (parent, args, ctx, info) => {
24+
return ctx.user.role === 'admin'
25+
},
26+
)
27+
28+
const isEditor = rule({ cache: 'contextual' })(
29+
async (parent, args, ctx, info) => {
30+
return ctx.user.role === 'editor'
31+
},
32+
)
33+
34+
// Permissions
35+
36+
const permissions = shield({
37+
Query: {
38+
frontPage: not(isAuthenticated),
39+
fruits: and(isAuthenticated, or(isAdmin, isEditor)),
40+
customers: and(isAuthenticated, isAdmin),
41+
},
42+
Mutation: {
43+
addFruitToBasket: isAuthenticated,
44+
},
45+
Fruit: isAuthenticated,
46+
Customer: isAdmin,
47+
})
48+
49+
// Server
50+
51+
const server = new GraphQLServer({
52+
typeDefs,
53+
resolvers,
54+
middlewares: [permissions],
55+
context: (req) => ({
56+
...req,
57+
user: getUser(req),
58+
}),
59+
})
60+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: SwiftGraphQL
3+
description: A GraphQL client that lets you forget about GraphQL.
4+
url: https://github.com/maticzav/swift-graphql
5+
github: maticzav/swift-graphql
6+
---
7+
8+
9+
SwiftGraphQL is a Swift code generator and a lightweight GraphQL client. It lets you create queries using Swift, and guarantees that every query you create is valid.
10+
11+
The library is centered around three core principles:
12+
13+
🚀 If your project compiles, your queries work.
14+
🦉 Use Swift in favour of GraphQL wherever possible.
15+
🌳 Your application model should be independent of your schema.
16+
17+
Here's a short preview of the SwiftGraphQL code
18+
19+
```swift
20+
import SwiftGraphQL
21+
22+
// Define a Swift model.
23+
struct Human: Identifiable {
24+
let id: String
25+
let name: String
26+
let homePlanet: String?
27+
}
28+
29+
// Create a selection.
30+
let human = Selection.Human {
31+
Human(
32+
id: try $0.id(),
33+
name: try $0.name(),
34+
homePlanet: try $0.homePlanet()
35+
)
36+
}
37+
38+
// Construct a query.
39+
let query = Selection.Query {
40+
try $0.humans(human.list)
41+
}
42+
43+
// Perform the query.
44+
send(query, to: "http://swift-graphql.heroku.com") { result in
45+
if let data = try? result.get() {
46+
print(data) // [Human]
47+
}
48+
}
49+
```

src/content/learn/Introduction.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ permalink: /learn/
77
next: /learn/queries/
88
---
99

10-
> Learn about GraphQL, how it works, and how to use it in this series of articles. Looking for documentation on how to build a GraphQL service? There are libraries to help you implement GraphQL in [many different languages](/code/). For an in-depth learning experience with practical tutorials, visit the [How to GraphQL](https://www.howtographql.com) fullstack tutorial website. We have also partnered with edX to create a free online course, [Exploring GraphQL: A Query Language for APIs](https://www.edx.org/course/exploring-graphql-a-query-language-for-apis).
10+
> Learn about GraphQL, how it works, and how to use it. Looking for documentation on how to build a GraphQL service?
11+
> There are libraries to help you implement GraphQL in [many different languages](/code/). For an in-depth learning experience
12+
> with practical tutorials, see [How to GraphQL](https://www.howtographql.com). Check out the
13+
> free online course,
14+
> [Exploring GraphQL: A Query Language for APIs](https://www.edx.org/course/exploring-graphql-a-query-language-for-apis).
1115
12-
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.
16+
GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your
17+
data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.
1318

14-
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:
19+
A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type.
20+
For example, a GraphQL service that tells you who the logged in user is (`me`) as well as that user's name might look
21+
like this:
1522

1623
```graphql
1724
type Query {
@@ -36,9 +43,11 @@ function User_name(user) {
3643
}
3744
```
3845

39-
Once a GraphQL service is running (typically at a URL on a web service), it can receive 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.
46+
After a GraphQL service is running (typically at a URL on a web service), it can receive GraphQL queries to validate and execute.
47+
The service first checks a query to ensure it only refers to the types and fields defined, and then runs the provided functions
48+
to produce a result.
4049

41-
For example the query:
50+
For example, the query:
4251

4352
```graphql
4453
{
@@ -48,7 +57,7 @@ For example the query:
4857
}
4958
```
5059

51-
Could produce the JSON result:
60+
Could produce the following JSON result:
5261

5362
```json
5463
{
@@ -58,4 +67,4 @@ Could produce the JSON result:
5867
}
5968
```
6069

61-
Learn more about GraphQL — the query language, type system, how the GraphQL service works, as well as best practices for using GraphQL in the articles written in this section; they help to solve common problems.
70+
To learn more, click **Continue Reading**.

0 commit comments

Comments
 (0)