Skip to content

Commit 2b93cb7

Browse files
mdubusgregberge
authored andcommitted
feat: documentation examples (#6)
1 parent 514e4dd commit 2b93cb7

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

packages/smooth/README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,150 @@ So far, we get:
7676
- Server rendering and indexing of `./pages`
7777
- Static file serving. `./static/` is mapped to `/static/` (given you [create a `./static/` directory](#static-file-serving-eg-images) inside your project)
7878

79+
80+
81+
### Structure
82+
83+
84+
#### GraphQL definitions
85+
86+
- Date
87+
- Datetime
88+
- Image
89+
- Link
90+
- Media
91+
92+
#### Types
93+
94+
- @content (will appear on your back-office)
95+
- @block (can be added to a page)
96+
- @field (can be filled by the user)
97+
98+
#### Schemas / Contents
99+
100+
In the contents folder, you can add all types that you want to appear on your back-office's menu
101+
102+
103+
Example :
104+
```js
105+
import gql from 'graphql-tag'
106+
107+
export const typeDefs = gql`
108+
type Actors {
109+
name: String! @field
110+
}
111+
112+
type Movie @content(slug: "movies", icon: "dashicons-admin-home") {
113+
title: String! @field
114+
description: String! @field(type: richText)
115+
cover: Image! @field
116+
actors: [Actors!]! @field
117+
}
118+
`
119+
120+
121+
```
122+
123+
#### Schemas / Blocks
124+
125+
The blocks folder is used to design your blocks, by describing all your types.
126+
Example :
127+
```js
128+
import gql from 'graphql-tag'
129+
130+
export const typeDefs = gql`
131+
type MovieListBlock @block {
132+
movies: [Movie!]!
133+
}
134+
`
135+
export const resolvers = {
136+
MovieListBlock: {
137+
movies: async (object, params, { api }) =>
138+
api.getContents({
139+
type: 'movies',
140+
}),
141+
},
142+
}
143+
144+
```
145+
146+
### Blocks
147+
148+
In this folder, you will define your block's fragment, and design it. It needs the same name as the one given it 'schemas/blocks'.
149+
150+
151+
Example :
152+
```js
153+
import React from 'react'
154+
import gql from 'graphql-tag'
155+
import { Link } from 'smooth/router'
156+
157+
export default function MovieListBlock({ movies }) {
158+
return (
159+
<div>
160+
{movies.map((movie, index) => (
161+
<Link to={`/movies/${movie.metadata.slug}`} key={index}>
162+
<div>{movie.title}</div>
163+
</Link>
164+
))}
165+
</div>
166+
)
167+
}
168+
169+
export const blockFragment = gql`
170+
fragment MovieListBlockProps on MovieListBlock {
171+
movies {
172+
metadata {
173+
slug
174+
}
175+
title
176+
description
177+
cover {
178+
url
179+
alt
180+
title
181+
}
182+
actors {
183+
name
184+
}
185+
}
186+
}
187+
`
188+
189+
```
190+
191+
### Pages
192+
193+
In this folder you can create all your content that will need a specific page.
194+
195+
```js
196+
197+
import React from 'react'
198+
import gql from 'graphql-tag'
199+
200+
export const contentFragment = gql`
201+
fragment MovieProps on Movie {
202+
title
203+
description
204+
cover {
205+
url
206+
alt
207+
}
208+
}
209+
`
210+
211+
export default function Movie({ title, description, cover }) {
212+
return (
213+
<div>
214+
<img src={cover.url} alt={cover.alt} style={{ maxWidth: 200 }} />
215+
<div>{title}</div>
216+
<div dangerouslySetInnerHTML={{ __html: description }} />
217+
</div>
218+
)
219+
}
220+
221+
```
222+
79223
### Content
80224

81225
#### Link to another content

0 commit comments

Comments
 (0)