Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pageSize option #456

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-prismic-previews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
"dependencies": {
"@imgix/gatsby": "^1.6.13",
"@prismicio/client": "6.0.0-beta.0",
"@prismicio/client": "6.0.0-alpha.8",
"@prismicio/helpers": "^2.0.0-beta.0",
"@prismicio/types": "^0.1.13",
"@reach/dialog": "^0.16.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const pluginOptionsSchema: NonNullable<
graphQuery: Joi.string(),
fetchLinks: Joi.array().items(Joi.string().required()),
lang: Joi.string().default(DEFAULT_LANG),
// TODO: Remove the hardcoded default once this PR to @prismicio/client is merged:
// https://github.com/prismicio/prismic-client/pull/195
pageSize: Joi.number().default(100),
imageImgixParams: Joi.object().default(DEFAULT_IMGIX_PARAMS),
imagePlaceholderImgixParams: Joi.object().default(
DEFAULT_PLACEHOLDER_IMGIX_PARAMS,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-prismic-previews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface PluginOptions extends gatsby.PluginOptions {
graphQuery?: string
fetchLinks?: string[]
lang: string
pageSize: number
imageImgixParams: imgixGatsby.ImgixUrlParams
imagePlaceholderImgixParams: imgixGatsby.ImgixUrlParams
typePrefix?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,16 @@ export const usePrismicPreviewBootstrap = (
lang: repositoryPluginOptions.lang,
fetchLinks: repositoryPluginOptions.fetchLinks,
graphQuery: repositoryPluginOptions.graphQuery,
pageSize: repositoryPluginOptions.pageSize,
},
})
client.enableAutoPreviews()

let allDocuments: prismicT.PrismicDocument[]
try {
allDocuments = await client.getAll()
allDocuments = await client.getAll({
pageSize: repositoryPluginOptions.pageSize,
})
} catch (error) {
if (
error instanceof prismic.ForbiddenError &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const usePrismicPreviewResolver = (
lang: repositoryPluginOptions.lang,
fetchLinks: repositoryPluginOptions.fetchLinks,
graphQuery: repositoryPluginOptions.graphQuery,
pageSize: repositoryPluginOptions.pageSize,
},
})
client.enableAutoPreviews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const createPluginOptions = (t: ava.ExecutionContext): PluginOptions => {
apiEndpoint: prismic.getEndpoint(repositoryName),
typePrefix: 'prefix',
lang: '*',
pageSize: 100,
toolbar: 'new',
imageImgixParams: { q: 100 },
imagePlaceholderImgixParams: { w: 10 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ test.serial('group', async (t) => {
)
})

test.serial('slices', async (t) => {
test.serial.only('slices', async (t) => {
const gatsbyContext = createGatsbyContext()
const pluginOptions = createPluginOptions(t)
const config = createRepositoryConfigs(pluginOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-prismic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"dependencies": {
"@imgix/gatsby": "^1.6.13",
"@prismicio/client": "6.0.0-beta.0",
"@prismicio/client": "6.0.0-alpha.8",
"@prismicio/custom-types-client": "^0.0.6",
"@prismicio/helpers": "^2.0.0-beta.0",
"@prismicio/types": "^0.1.13",
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-prismic/src/buildDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const buildDependencies = (
lang: pluginOptions.lang,
fetchLinks: pluginOptions.fetchLinks,
graphQuery: pluginOptions.graphQuery,
pageSize: pluginOptions.pageSize,
},
})

Expand Down
8 changes: 7 additions & 1 deletion packages/gatsby-source-prismic/src/lib/queryAllDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ export const queryAllDocuments: RTE.ReaderTaskEither<
prismicT.PrismicDocument[]
> = pipe(
RTE.ask<Dependencies>(),
RTE.chain((env) => RTE.fromTask(() => env.prismicClient.getAll())),
RTE.chain((env) =>
RTE.fromTask(() =>
env.prismicClient.getAll({
pageSize: env.pluginOptions.pageSize,
}),
),
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ export const queryDocumentsByIds = (
): RTE.ReaderTaskEither<Dependencies, Error, prismicT.PrismicDocument[]> =>
pipe(
RTE.ask<Dependencies>(),
RTE.chain((env) => RTE.fromTask(() => env.prismicClient.getAllByIDs(ids))),
RTE.chain((env) =>
RTE.fromTask(() =>
env.prismicClient.getAllByIDs(ids, {
pageSize: env.pluginOptions.pageSize,
}),
),
),
)
7 changes: 5 additions & 2 deletions packages/gatsby-source-prismic/src/plugin-options-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export const pluginOptionsSchema: NonNullable<
fetchLinks: Joi.array().items(Joi.string().required()),
graphQuery: Joi.string(),
lang: Joi.string().default(DEFAULT_LANG),
// TODO: Remove the hardcoded default once this PR to @prismicio/client is merged:
// https://github.com/prismicio/prismic-client/pull/195
pageSize: Joi.number().default(100),
linkResolver: Joi.function(),
htmlSerializer: Joi.function(),
schemas: Joi.object(),
Expand All @@ -209,8 +212,8 @@ export const pluginOptionsSchema: NonNullable<
createRemoteFileNode: Joi.function().default(
() => gatsbyFs.createRemoteFileNode,
),
transformFieldName: Joi.function().default(() => (fieldName: string) =>
fieldName.replace(/-/g, '_'),
transformFieldName: Joi.function().default(
() => (fieldName: string) => fieldName.replace(/-/g, '_'),
),
fetch: Joi.function().default(() => fetch),
})
Expand Down
5 changes: 3 additions & 2 deletions packages/gatsby-source-prismic/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface PluginOptions extends gatsby.PluginOptions {
graphQuery?: string
fetchLinks?: string[]
lang: string
pageSize?: number
linkResolver?: prismicH.LinkResolverFunction
htmlSerializer?: prismicH.HTMLFunctionSerializer | prismicH.HTMLMapSerializer
schemas: Record<string, prismicT.CustomTypeModelDefinition>
Expand All @@ -86,7 +87,7 @@ export interface PluginOptions extends gatsby.PluginOptions {
}

export type FieldConfigCreator<
TSchema extends prismicT.CustomTypeModelField = prismicT.CustomTypeModelField
TSchema extends prismicT.CustomTypeModelField = prismicT.CustomTypeModelField,
> = (
path: string[],
schema: TSchema,
Expand Down Expand Up @@ -188,7 +189,7 @@ interface PrismicWebhookExperimentVariation {
export type PrismicCustomTypeApiResponse = PrismicCustomTypeApiCustomType[]

export interface PrismicCustomTypeApiCustomType<
Model extends prismicT.CustomTypeModel = prismicT.CustomTypeModel
Model extends prismicT.CustomTypeModel = prismicT.CustomTypeModel,
> {
id: string
label: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createPluginOptions = (t: ava.ExecutionContext): PluginOptions => {
typePrefix: 'prefix',
schemas: {},
lang: DEFAULT_LANG,
pageSize: 100,
webhookSecret: 'secret',
imageImgixParams: DEFAULT_IMGIX_PARAMS,
imagePlaceholderImgixParams: DEFAULT_PLACEHOLDER_IMGIX_PARAMS,
Expand Down
13 changes: 6 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2919,20 +2919,19 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353"
integrity sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q==

"@prismicio/client@6.0.0-beta.0":
version "6.0.0-beta.0"
resolved "https://registry.yarnpkg.com/@prismicio/client/-/client-6.0.0-beta.0.tgz#b43a207775bfc2f70a3d30138ad239a689bf5acf"
integrity sha512-MGKxEao/CeqjuBaKrNovtoFl6D/EClfHnCBaL8c50nD2kQJz8BziC8cHUAw/8eWqEFnJXLvLCP5NKiks+s3log==
"@prismicio/client@6.0.0-alpha.8":
version "6.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@prismicio/client/-/client-6.0.0-alpha.8.tgz#fdd086032e823b964ef63651b4a2aa9bedf29109"
integrity sha512-zp3c8mZ/Sm2tQdZCASGEEx2UGJnYS1elFwTEca7M2y/Qi3hPM+Agp4xNMM5UoAg+2m1VFAt151vfaEscc5q4Gw==
dependencies:
"@prismicio/helpers" "^2.0.0-alpha.9"
"@prismicio/types" "^0.1.13"
"@prismicio/helpers" "^2.0.0-alpha.3"

"@prismicio/custom-types-client@^0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@prismicio/custom-types-client/-/custom-types-client-0.0.6.tgz#774e1498b88a07b817292a5894208851c5dd4635"
integrity sha512-/QeHmNzEtOMtEAZF7ZfRSSosSXGhA4dzQm7vczhxdBGIT23Bbj+h0I4hNlpJZ4n0UzmIYWtd45jYCguVo3hfqQ==

"@prismicio/helpers@^2.0.0-alpha.9", "@prismicio/helpers@^2.0.0-beta.0":
"@prismicio/helpers@^2.0.0-alpha.3", "@prismicio/helpers@^2.0.0-beta.0":
version "2.0.0-beta.0"
resolved "https://registry.yarnpkg.com/@prismicio/helpers/-/helpers-2.0.0-beta.0.tgz#493d07f81bde06d76928af94e99672ac9f429962"
integrity sha512-2WLXcS9Q/8JU7maNo/3cUSsUKnjUMpuZTxVxCSaDxDcBACrXR3T2nSJKvzcO5jS5zzpAkJG6zCdjP3dQVRwPmw==
Expand Down