# Dynamic queries with gatsby-source-prismic

**URL:** <https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313>\
**Category:** Developing with Prismic\
**Tags:** gatsby\
**Created:** [December 22, 2020, 2:21am UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313 "2020-12-22T02:21:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.martens](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@alex.martens](https://community.prismic.io/u/alex.martens)\
**Post date:** [December 22, 2020, 2:21am UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/1 "2020-12-22T02:21:44Z")

</div>

The gatsby-source-prismic-graphql allowed you to dynamically fetch data by applying values to the variables defined in your page query. This was done using using 'prismic.load'. How can this be done using the recommended gatsby-source-prismic plugin?

Here is the example from the gatsby-source-prismic-graphql documentation:

```
import React from 'react';
import { graphql } from 'gatsby';

export const query = graphql`
  query Example($limit: Int) {
    prismic {
      allArticles(first: $limit) {
        edges {
          node {
            title
          }
        }
      }
    }
  }
`;

export default function Example({ data, prismic }) {
  const handleClick = () =>
    prismic.load({
      variables: { limit: 20 },
      query, // (optional)
      fragments: [], // (optional)
    });

  return (
    // ... data
    <button onClick={handleClick}>load more</button>
  );
}

```

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [December 22, 2020, 2:37am UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/2 "2020-12-22T02:37:25Z")

</div>

Hello Alex, thanks for reaching out

These are done in the 'traditional Gatsby way' by using the `gatsby-node` file rather than in the configuration of the actual plugin in the `gatsby-config` file.

[Here's the example of how you do it in this plugin](https://www.gatsbyjs.com/plugins/gatsby-source-prismic/?=prismic#sites-gatsby-nodejs-example). And also, the docs for Gatsby Node APIs:

> **[Gatsby Node APIs](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/)**
>
> Documentation on Node APIs used in Gatsby build process for common uses like creating pages

---

<div class="post-metadata">

**Author:** ![alex.martens](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@alex.martens](https://community.prismic.io/u/alex.martens)\
**Post date:** [December 22, 2020, 2:22pm UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/4 "2020-12-22T14:22:23Z")

</div>

Thank you for your response Paulina. The problem with doing this solely at build time is that, we are going to have several possible filters that could be applied, plus pagination on top of that. Generating pages for all of these possible scenarios seems a bit cumbersome, not to mention inelegant. gatsby-source-prismic-graphql let you simply to reuse the existing query and provide arguments to it. Is there anyway to do this with the gatsby-source-prismic plugin?

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [December 22, 2020, 5:20pm UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/5 "2020-12-22T17:20:11Z")

</div>

I understand, and I do see why this was a useful tool in the other plugin, but usually CMS source plugins are just that and they do not handle createPages for you. So `gatsby-source-prismic` is actually more aligned with with Gatsby concepts of building pages.

You can pass context to the dynamic queries of your pages via `gatsby-node`, but then again as you said before, you need to pass the arguments to it afterwards.

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [December 30, 2020, 5:59am UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/6 "2020-12-30T05:59:06Z")

</div>

This issue has been closed due to inactivity. [Flag to reopen](https://community.prismic.io/t/re-open-a-thread/2175).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 4:48pm UTC](https://community.prismic.io/t/dynamic-queries-with-gatsby-source-prismic/3313/7 "2021-12-09T16:48:14Z")

</div>


