Skip to content

Commit 348288f

Browse files
authored
Merge pull request #10 from smooth-code/queries
Queries
2 parents 2b93cb7 + d3c3843 commit 348288f

File tree

30 files changed

+1795
-968
lines changed

30 files changed

+1795
-968
lines changed

examples/wordpress/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
ports:
2323
- '8000:80'
2424
environment:
25-
WP_HOME: http://localhost:3001
25+
WP_HOME: http://localhost:3000
2626
WP_DEFAULT_THEME: smooth-js
2727
WORDPRESS_DB_HOST: mysql:3306
2828
WORDPRESS_DB_USER: wordpress

examples/wordpress/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "WP_HOME=http://localhost:3001 smooth dev"
4+
"dev": "WP_HOME=http://localhost:3000 smooth dev"
55
},
66
"dependencies": {
77
"graphql-tag": "^2.10.1",
88
"react": "^16.8.2",
99
"react-dom": "^16.8.2",
10+
"smooth": "latest",
1011
"smooth-backend-wordpress": "latest",
11-
"smooth-plugin-head-meta": "latest",
12-
"smooth": "latest"
12+
"smooth-plugin-head-meta": "latest"
13+
},
14+
"resolutions": {
15+
"apollo-link-dedup": "1.0.15"
1316
}
1417
}

examples/wordpress/src/_app.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react'
2+
import gql from 'graphql-tag'
3+
import { Query } from 'smooth/query'
4+
5+
const PAGE = gql`
6+
query Page {
7+
page(slug: "test") {
8+
title
9+
}
10+
}
11+
`
12+
13+
export default function Page({ Component, ...props }) {
14+
return (
15+
<Query query={PAGE}>
16+
{({ data }) =>
17+
data && (
18+
<>
19+
<h1>{data.page.title}</h1>
20+
<Component {...props} />
21+
</>
22+
)
23+
}
24+
</Query>
25+
)
26+
}

examples/wordpress/src/pages/foo$.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
export default () => 'hello'
1+
import React from 'react'
2+
import gql from 'graphql-tag'
3+
import { Query } from 'smooth/query'
4+
import { useLang } from 'smooth/page'
5+
6+
const PAGE = gql`
7+
query Page($foo: String) {
8+
page(slug: "test") {
9+
title
10+
}
11+
}
12+
`
13+
14+
export default function Page() {
15+
const lang = useLang()
16+
return (
17+
<>
18+
<div>Lang: {lang}</div>
19+
<Query query={PAGE}>
20+
{({ data }) => (data ? data.page.title : null)}
21+
</Query>
22+
</>
23+
)
24+
}

examples/wordpress/src/pages/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const contentFragment = gql`
2828
blocks {
2929
...BlockFragment
3030
}
31+
metadata {
32+
id
33+
slug
34+
}
3135
}
3236
3337
${BlockFragment}

examples/wordpress/src/pages/test$.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import gql from 'graphql-tag'
3+
4+
export const contentFragment = gql`
5+
fragment PageProps on Page {
6+
title
7+
}
8+
`
9+
10+
export default function Page({ title }) {
11+
return (
12+
<div>
13+
<h2>Title</h2>
14+
<div>{title}</div>
15+
</div>
16+
)
17+
}

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
},
1616
"devDependencies": {
1717
"@babel/cli": "^7.2.3",
18-
"@babel/core": "^7.3.4",
19-
"@babel/plugin-proposal-class-properties": "^7.3.4",
20-
"@babel/preset-env": "^7.3.4",
18+
"@babel/core": "^7.4.0",
19+
"@babel/plugin-proposal-class-properties": "^7.4.0",
20+
"@babel/preset-env": "^7.4.1",
2121
"@babel/preset-react": "^7.0.0",
22-
"@loadable/babel-plugin": "^5.6.0",
22+
"@loadable/babel-plugin": "^5.7.2",
2323
"babel-core": "^7.0.0-bridge.0",
2424
"babel-eslint": "^10.0.1",
25-
"babel-jest": "^24.1.0",
25+
"babel-jest": "^24.5.0",
2626
"conventional-github-releaser": "^3.1.2",
2727
"cross-env": "^5.2.0",
2828
"doctoc": "^1.4.0",
29-
"eslint": "^5.15.0",
29+
"eslint": "^5.15.3",
3030
"eslint-config-airbnb": "^17.1.0",
3131
"eslint-config-prettier": "^4.1.0",
3232
"eslint-config-smooth": "^2.0.0",
3333
"eslint-plugin-import": "^2.16.0",
3434
"eslint-plugin-jsx-a11y": "^6.2.1",
3535
"eslint-plugin-react": "^7.12.4",
36-
"eslint-plugin-react-hooks": "^1.4.0",
37-
"jest": "^24.1.0",
36+
"eslint-plugin-react-hooks": "^1.5.1",
37+
"jest": "^24.5.0",
3838
"lerna": "^3.13.1",
3939
"prettier": "^1.16.4",
40-
"react": "^16.8.3",
41-
"react-dom": "^16.8.3",
40+
"react": "^16.8.4",
41+
"react-dom": "^16.8.4",
4242
"shx": "^0.3.2"
4343
}
4444
}

packages/smooth-backend-wordpress/src/acf/resolvers/createDefaultResolvers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function getQueryFieldResolver(node, helpers, state) {
9191
}
9292
const type = t.getContentSlug(typeDef)
9393
return {
94-
async [name](object, { slug, lang, id, preview }) {
94+
async [name](object, { slug }, { lang, id, preview }) {
9595
if (preview) {
9696
return state.apiClient.getContentPreview({
9797
type,
@@ -100,7 +100,9 @@ function getQueryFieldResolver(node, helpers, state) {
100100
})
101101
}
102102

103-
return state.apiClient.getContent({ type, lang, slug })
103+
const res = await state.apiClient.getContent({ type, lang, slug })
104+
105+
return res
104106
},
105107
}
106108
}

packages/smooth-dev-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
"react-dom": ">=16.3.0"
3333
},
3434
"dependencies": {
35-
"@babel/runtime": "^7.3.4",
35+
"@babel/runtime": "^7.4.0",
3636
"chokidar": "^2.1.2",
3737
"configstore": "^4.0.0",
3838
"fs-extra": "^7.0.1",
3939
"is-absolute": "^1.0.0",
4040
"lodash": "^4.17.10",
41-
"yargs": "^13.2.1"
41+
"yargs": "^13.2.2"
4242
}
4343
}

0 commit comments

Comments
 (0)