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

Commit

Permalink
fix: sortBy works for all document types
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonfancher committed Jul 12, 2019
1 parent e621a76 commit d861c9d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/gatsby-source-prismic-graphql/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ function createDocumentPages(
});
}

const getDocumentsQuery = ({ documentType }: { documentType: string }): string => `
query AllPagesQuery ($after: String, $lang: String, $sortBy: PRISMIC_SortPosty) {
const getDocumentsQuery = ({
documentType,
sortType,
}: {
documentType: string;
sortType: string;
}): string => `
query AllPagesQuery ($after: String, $lang: String, $sortBy: ${sortType}) {
prismic {
${documentType} (
first: 20
Expand Down Expand Up @@ -158,7 +164,8 @@ exports.createPages = async ({ graphql, actions: { createPage } }: any, options:
documents: [any?] = []
): Promise<any> {
const documentType = `all${page.type}s`;
const query = getDocumentsQuery({ documentType });
const sortType = `PRISMIC_Sort${page.type}y`;
const query = getDocumentsQuery({ documentType, sortType });

const { data, errors } = await graphql(query, {
after: endCursor,
Expand Down Expand Up @@ -189,9 +196,6 @@ exports.createPages = async ({ graphql, actions: { createPage } }: any, options:

// Create all the pages!
const pages = options.pages || [];

// TODO: Decide whether options.defaultLang should be required. If not, what does it default to?
// allQueries accept `null` as the lang. Post does not.
const pageCreators: Promise<any>[] = [];
pages.forEach(
(page: Page): void => {
Expand Down

0 comments on commit d861c9d

Please sign in to comment.