Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
fix: pageContext as variables by default
Browse files Browse the repository at this point in the history
  • Loading branch information
birkir committed Feb 25, 2019
1 parent ecd1a09 commit 0cd8d57
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
37 changes: 37 additions & 0 deletions example/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,40 @@
*/

// You can delete this file if you're not using it

const path = require('path');

exports.createPages = ({ graphql, actions }) => {

const { createPage } = actions

return new Promise((resolve, reject) => {
graphql(`
query {
prismic {
allAuthors {
edges {
node {
_meta {
id
}
name
}
}
}
}
}
`).then(result => {
result.data.prismic.allAuthors.edges.forEach(({ node }) => {
createPage({
path: node._meta.id,
component: path.resolve(`./src/templates/author.js`),
context: {
id: node._meta.id,
},
})
})
resolve()
})
})
}
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"gatsby-plugin-manifest": "^2.0.2",
"gatsby-plugin-offline": "^2.0.5",
"gatsby-plugin-react-helmet": "^3.0.0",
"gatsby-source-prismic-graphql": "./..",
"gatsby-source-prismic-graphql": "2.1.1",
"react": "^16.5.1",
"react-dom": "^16.5.1",
"react-helmet": "^5.2.0"
Expand All @@ -28,7 +28,7 @@
"prettier": "^1.14.2"
},
"resolutions": {
"graphql": "14.0.2"
"graphql": "0.13.2"
},
"repository": {
"type": "git",
Expand Down
18 changes: 10 additions & 8 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4346,8 +4346,10 @@ gatsby-source-graphql@^2.0.8:
node-fetch "^1.7.3"
uuid "^3.1.0"

gatsby-source-prismic-graphql@./..:
version "2.1.0"
[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/gatsby-source-prismic-graphql/-/gatsby-source-prismic-graphql-2.1.1.tgz#a278937e0a8e7096fe6268b4bcf0ce080577874f"
integrity sha512-xDPeVzERb7JzvtL+i0OJIO1MeCZvCWFeOmexx901WR8ApVZrLBgaP+nkPJ6uH1SH69qDX8YXmnKHMsHr+lD2tQ==
dependencies:
apollo-boost "0.1.28"
apollo-link-context "1.0.14"
Expand Down Expand Up @@ -4744,12 +4746,12 @@ graphql-type-json@^0.2.1:
resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.2.1.tgz#d2c177e2f1b17d87f81072cd05311c0754baa420"
integrity sha1-0sF34vGxfYf4EHLNBTEcB1S6pCA=

graphql@14.0.2, graphql@^14.0.2, graphql@^14.1.1:
version "14.0.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.0.2.tgz#7dded337a4c3fd2d075692323384034b357f5650"
integrity sha512-gUC4YYsaiSJT1h40krG3J+USGlwhzNTXSb4IOZljn9ag5Tj+RkoXrWp+Kh7WyE3t1NCfab5kzCuxBIvOMERMXw==
graphql@0.13.2, graphql@^14.0.2, graphql@^14.1.1:
version "0.13.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
integrity sha512-QZ5BL8ZO/B20VA8APauGBg3GyEgZ19eduvpLWoq5x7gMmWnHoy8rlQWPLmWgFvo1yNgjSEFMesmS4R6pPr7xog==
dependencies:
iterall "^1.2.2"
iterall "^1.2.1"

gud@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -5670,7 +5672,7 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=

iterall@^1.1.3, iterall@^1.2.2:
iterall@^1.1.3, iterall@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
integrity sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-source-prismic-graphql",
"version": "2.1.0",
"version": "2.2.0",
"description": "Source data from Prismic with GraphQL",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions src/withPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { PrismicLink, getCookies, fieldName, typeName } from './utils';
interface IPreviewProps {
children?: any;
data: any;
pageContext: {
[key: string]: any;
};
prismic: {
loading: boolean;
error: any;
Expand Down Expand Up @@ -73,15 +76,14 @@ export function withPreview<P extends object>(
}
}

load = async (variables?: { [key: string]: string }) => {
load = async (variables: { [key: string]: string } = this.props.pageContext) => {
const client = getClient();
try {
this.setState({ loading: true, error: false });
console.log('ELO', client, variables);
const res = await client.query({
query: getIsolatedQuery(query, fieldName, typeName),
fetchPolicy: 'network-only',
variables
variables,
});

if (!res.errors && res.data) {
Expand Down

0 comments on commit 0cd8d57

Please sign in to comment.