Skip to content

Commit cd98c96

Browse files
committed
feat: expose Query
1 parent 2b93cb7 commit cd98c96

File tree

26 files changed

+884
-541
lines changed

26 files changed

+884
-541
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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",
@@ -10,5 +10,8 @@
1010
"smooth-backend-wordpress": "latest",
1111
"smooth-plugin-head-meta": "latest",
1212
"smooth": "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 prefetch={false} 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: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
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+
throw new Error('kk')
17+
return (
18+
<>
19+
<div>Lang: {lang}</div>
20+
<Query query={PAGE}>
21+
{({ data }) => (data ? data.page.title : null)}
22+
</Query>
23+
</>
24+
)
25+
}

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}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
"@babel/plugin-proposal-class-properties": "^7.3.4",
2020
"@babel/preset-env": "^7.3.4",
2121
"@babel/preset-react": "^7.0.0",
22-
"@loadable/babel-plugin": "^5.6.0",
22+
"@loadable/babel-plugin": "^5.7.0",
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.1",
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.0",
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
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
}

packages/smooth/apollo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* eslint-disable import/no-unresolved */
2+
module.exports = require('./lib/apollo')

packages/smooth/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@
4141
"@babel/preset-react": "^7.0.0",
4242
"@babel/register": "^7.0.0",
4343
"@babel/runtime": "^7.3.4",
44-
"@emotion/core": "^10.0.7",
45-
"@loadable/babel-plugin": "^5.6.0",
46-
"@loadable/component": "^5.6.1",
47-
"@loadable/server": "^5.6.1",
48-
"@loadable/webpack-plugin": "^5.5.0",
44+
"@emotion/core": "^10.0.9",
45+
"@loadable/babel-plugin": "^5.7.0",
46+
"@loadable/component": "^5.7.0",
47+
"@loadable/server": "^5.7.0",
48+
"@loadable/webpack-plugin": "^5.7.0",
4949
"apollo-cache-inmemory": "^1.5.1",
5050
"apollo-client": "^2.5.1",
51-
"apollo-link": "^1.2.8",
52-
"apollo-link-http": "^1.5.11",
53-
"apollo-link-schema": "^1.1.6",
51+
"apollo-link": "^1.2.10",
52+
"apollo-link-http": "^1.5.13",
53+
"apollo-link-schema": "^1.2.1",
5454
"apollo-server-express": "^2.4.8",
5555
"axios": "^0.18.0",
5656
"babel-loader": "^8.0.5",
57-
"camelcase": "^5.1.0",
57+
"camelcase": "^5.2.0",
5858
"commander": "^2.19.0",
5959
"cors": "^2.8.5",
6060
"cwd": "^0.10.0",
@@ -66,18 +66,18 @@
6666
"graphql-tag": "^2.10.1",
6767
"graphql-tools": "^4.0.4",
6868
"history": "^4.7.2",
69-
"humanize-string": "^1.0.2",
69+
"humanize-string": "^2.0.0",
7070
"merge-deep": "^3.0.2",
7171
"pluralize": "^7.0.0",
7272
"progress-estimator": "^0.2.2",
7373
"query-string": "^6.3.0",
74-
"react-apollo": "^2.5.1",
74+
"react-apollo": "^2.5.2",
7575
"react-helmet": "^5.2.0",
7676
"react-router-dom": "^4.3.1",
7777
"slugify": "^1.3.4",
7878
"tiny-glob": "^0.2.6",
7979
"webpack": "^4.29.6",
80-
"webpack-dev-middleware": "^3.6.0",
80+
"webpack-dev-middleware": "^3.6.1",
8181
"webpack-hot-middleware": "^2.24.3",
8282
"webpack-node-externals": "^1.7.2"
8383
}

0 commit comments

Comments
 (0)