Skip to content

Commit 9165c81

Browse files
docs(website): add graphql docs
1 parent 0a60632 commit 9165c81

File tree

8 files changed

+518
-0
lines changed

8 files changed

+518
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/index.ts',
6+
code: `
7+
import { state } from './state'
8+
9+
export const config = {
10+
state
11+
}
12+
`,
13+
},
14+
{
15+
fileName: 'overmind/state.ts',
16+
code: `
17+
// We will talk about this one soon :)
18+
import { Post } from './graphql-types'
19+
20+
type State = {
21+
posts: Post[]
22+
}
23+
24+
export const state: State = {
25+
posts: []
26+
}
27+
`,
28+
},
29+
]
30+
: [
31+
{
32+
fileName: 'overmind/index.js',
33+
code: `
34+
import { state } from './state'
35+
36+
export const config = {
37+
state
38+
}
39+
`,
40+
},
41+
{
42+
fileName: 'overmind/state.js',
43+
code: `
44+
export const state = {
45+
posts: []
46+
}
47+
`,
48+
},
49+
]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/actions.ts',
6+
code: `
7+
import { AsyncAction } from 'overmind'
8+
9+
export const getPosts: AsyncAction = async ({ state, effects }) => {
10+
const { posts } = await effects.queries.posts()
11+
12+
state.posts = posts
13+
}
14+
15+
export const addPost: AsyncAction<string> = async ({ effects }, title) => {
16+
await effects.mutations.createPost({ title })
17+
}
18+
`,
19+
},
20+
]
21+
: [
22+
{
23+
fileName: 'overmind/actions.js',
24+
code: `
25+
export const getPosts = async ({ state, effects }) => {
26+
const { posts } = await effects.queries.posts()
27+
28+
state.posts = posts
29+
}
30+
31+
export const addPost = async ({ effects }, title) => {
32+
await effects.mutations.createPost({ title })
33+
}
34+
`,
35+
},
36+
]
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/index.ts',
6+
code: `
7+
import { graphql } from 'overmind-graphql'
8+
import * as queries from './queries'
9+
import * as mutations from './mutations'
10+
import { state } from './state'
11+
12+
export const config = graphql({
13+
state
14+
}, {
15+
endpoint: 'http://some-endpoint.dev',
16+
queries,
17+
mutations
18+
})
19+
`,
20+
},
21+
{
22+
fileName: 'overmind/queries.ts',
23+
code: `
24+
import { Query, gql } from 'overmind-graphql'
25+
import { Posts } from './graphql-types'
26+
27+
export const posts: Query<Posts> = gql\`
28+
query Posts {
29+
posts {
30+
id
31+
title
32+
}
33+
}
34+
\`;
35+
`,
36+
},
37+
{
38+
fileName: 'overmind/mutations.ts',
39+
code: `
40+
import { Query, gql } from 'overmind-graphql'
41+
import { CreatePost, CreatePostVariables } from './graphql-types'
42+
43+
export const createPost: Query<CreatePost, CreatePostVariables> = gql\`
44+
mutation CreatePost($title: String!) {
45+
createPost(title: $title) {
46+
id
47+
}
48+
}
49+
\`
50+
`,
51+
},
52+
]
53+
: [
54+
{
55+
fileName: 'overmind/index.js',
56+
code: `
57+
import { graphql } from 'overmind-graphql'
58+
import * as queries from './queries'
59+
import * as mutations from './mutations'
60+
import { state } from './state'
61+
62+
export const config = graphql({
63+
state
64+
}, {
65+
endpoint: 'http://some-endpoint.dev',
66+
queries,
67+
mutations
68+
})
69+
`,
70+
},
71+
{
72+
fileName: 'overmind/queries.js',
73+
code: `
74+
import { gql } from 'overmind-graphql'
75+
76+
export const posts = gql\`
77+
query Posts {
78+
posts {
79+
id
80+
title
81+
}
82+
}
83+
\`;
84+
`,
85+
},
86+
{
87+
fileName: 'overmind/mutations.ts',
88+
code: `
89+
import { gql } from 'overmind-graphql'
90+
91+
export const createPost = gql\`
92+
mutation CreatePost($title: String!) {
93+
createPost(title: $title) {
94+
id
95+
}
96+
}
97+
\`
98+
`,
99+
},
100+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/index.ts',
6+
code: `
7+
import { graphql } from 'overmind-graphql'
8+
import * as queries from './queries'
9+
import * as mutations from './mutations'
10+
import { state } from './state'
11+
12+
export const config = graphql({
13+
state
14+
}, {
15+
endpoint: 'http://some-endpoint.dev',
16+
headers: (state) => ({
17+
authorization: \`Bearer \${state.auth.token}\`
18+
}),
19+
queries,
20+
mutations
21+
})
22+
`,
23+
},
24+
]
25+
: [
26+
{
27+
fileName: 'overmind/index.js',
28+
code: `
29+
import { graphql } from 'overmind-graphql'
30+
import * as queries from './queries'
31+
import * as mutations from './mutations'
32+
import { state } from './state'
33+
34+
export const config = graphql({
35+
state
36+
}, {
37+
endpoint: 'http://some-endpoint.dev',
38+
headers: (state) => ({
39+
authorization: \`Bearer \${state.auth.token}\`
40+
}),
41+
queries,
42+
mutations
43+
})
44+
`,
45+
},
46+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/actions.ts',
6+
code: `
7+
import { AsyncAction } from 'overmind'
8+
9+
export const getPosts: AsyncAction = async ({ state, effects }) => {
10+
const { posts } = await effects.queries.posts()
11+
12+
state.posts = posts
13+
}
14+
15+
export const addPost: AsyncAction<string> = async ({ state, effects }, title) => {
16+
const optimisticId = String(Date.now())
17+
18+
state.posts.push({
19+
id: optimisticId,
20+
title
21+
})
22+
23+
const { id } = await effects.mutations.createPost({ title })
24+
const optimisticPost = state.posts.find(post => post.id === optimisticId)
25+
26+
optimisticPost.id = id
27+
}
28+
`,
29+
},
30+
]
31+
: [
32+
{
33+
fileName: 'overmind/actions.js',
34+
code: `
35+
export const getPosts = async ({ state, effects }) => {
36+
const { posts } = await effects.queries.posts()
37+
38+
state.posts = posts
39+
}
40+
41+
export const addPost = async ({ state, effects }, title) => {
42+
const optimisticId = String(Date.now())
43+
44+
state.posts.push({
45+
id: optimisticId,
46+
title
47+
})
48+
49+
const { id } = await effects.mutations.createPost({ title })
50+
const optimisticPost = state.posts.find(post => post.id === optimisticId)
51+
52+
optimisticPost.id = id
53+
}
54+
`,
55+
},
56+
]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/index.ts',
6+
code: `
7+
import { graphql } from 'overmind-graphql'
8+
import * as queries from './queries'
9+
import * as mutations from './mutations'
10+
import { state } from './state'
11+
12+
export const config = graphql({
13+
state
14+
}, {
15+
endpoint: 'http://some-endpoint.dev',
16+
headers: (state) => ({
17+
authorization: \`Bearer \${state.auth.token}\`
18+
}),
19+
options: {
20+
credentials: 'include',
21+
mode: 'cors',
22+
},
23+
queries,
24+
mutations
25+
})
26+
`,
27+
},
28+
]
29+
: [
30+
{
31+
fileName: 'overmind/index.js',
32+
code: `
33+
import { graphql } from 'overmind-graphql'
34+
import * as queries from './queries'
35+
import * as mutations from './mutations'
36+
import { state } from './state'
37+
38+
export const config = graphql({
39+
state
40+
}, {
41+
endpoint: 'http://some-endpoint.dev',
42+
headers: (state) => ({
43+
authorization: \`Bearer \${state.auth.token}\`
44+
}),
45+
options: {
46+
credentials: 'include',
47+
mode: 'cors',
48+
},
49+
queries,
50+
mutations
51+
})
52+
`,
53+
},
54+
]

0 commit comments

Comments
 (0)