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

Commit

Permalink
feat: add support for passing sortBy for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonfancher committed Jul 12, 2019
1 parent a3c06db commit aa893b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/gatsby-source-prismic-graphql/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ exports.sourceNodes = (ref: any, options: PluginOptions) => {
return sourceNodes(ref, opts);
};

const getPagesQuery = ({ pageType }: { pageType: string }) => `
const getPagesQuery = ({ pageType, page }: { pageType: string; page: any }) => `
query AllPagesQuery (
$after: String
) {
prismic {
${pageType} (
first: 20
after: $after
sortBy: ${page.sortBy || 'meta_lastPublicationDate_ASC'}
) {
totalCount
pageInfo {
Expand Down Expand Up @@ -88,7 +89,7 @@ exports.createPages = async ({ graphql, actions: { createPage } }: any, options:
// (Prismic GraphQL queries only return up to 20 results per query)
async function createPageRecursively(page: any, endCursor: string = '') {
const pageType = `all${page.type}s`;
const query = getPagesQuery({ pageType });
const query = getPagesQuery({ pageType, page });
const { data, errors } = await graphql(query, { after: endCursor });
const rootQuery = getRootQuery(page.component);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Page {
path: string;
component: string;
lang?: string;
sortBy?: string;
}

export interface PluginOptions {
Expand Down

0 comments on commit aa893b4

Please sign in to comment.