# Querying an empty slice using GraphQuery

**URL:** <https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424>\
**Category:** Developing with Prismic\
**Tags:** javascript\
**Created:** [March 9, 2021, 12:47am UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424 "2021-03-09T00:47:25Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 9, 2021, 12:47am UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/1 "2021-03-09T00:47:25Z")

</div>

Hi, I'm trying to query empty slices using GraphQuery (fetchLinks v2) in a Next.js app. However, when I query, the API throws an error:

```auto
Unable to parse fetch query Invalid fetch parsing Exception.\n\nInvalid input '}', expected NewLine (line 108, column 17):\n non-repeat {}\n ^\n\n4 rules mismatched at error location:\n

```

The query itself looks something like this:

```nohighlight
`... on games_section {
    non-repeat {}
    repeat {}
  }`

```

Is querying an empty slice supported and if not, can it be supported?

Thank you

---

<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:** [March 9, 2021, 2:50am UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/2 "2021-03-09T02:50:25Z")

</div>

Hello, You can retrieve the slices of a document, but you need to specify the fields inside the actual Slice instead of adding empty objects.

Which fields are you using inside your Slices?

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 9, 2021, 3:08am UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/4 "2021-03-09T03:08:09Z")

</div>

Hi @Paulina, thank you for the reply.

So it might sound weird, but I don't really need any fields. For example, if I want a divider between two sections, I would have a Divider (`<hr />`) slice and that would be added between two slices. My `Games Section` slice is basically a placeholder.

---

<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:** [March 9, 2021, 8:17pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/5 "2021-03-09T20:17:30Z")

</div>

Ok, I see. Your query needs to look for all fields in a slice in the given Custom type.

For example, in this GraphQuery, I'm querying for documents of the type `blog` that have a Content Relationship field with the API ID of `example_content_relationship` with a linked document of the type `post` that has a Slice with the name of `example_divider_slice`

```auto
        const mySuperGraphQuery = `{
          blog {
            example_content_relationship {
              ...on post {
                body{
                  ...on example_divider_slice {
                    non-repeat {
                      ...non-repeatFields
                    }
                    repeat {
                      ...repeatFields
                    }
                  }
                }
              }
            }
          }
        }
        `

        const BlogPosts = await client
          .getByUID('blog', uid, { graphQuery: mySuperGraphQuery })
          .then(function (document) {
            console.log(document)
          })

```

Note that uid is a dynamic value in this example.

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 9, 2021, 8:36pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/6 "2021-03-09T20:36:17Z")

</div>

@Pau My query looks very similar to your example, but it still throws an error when I try it. My query looks something like the following:

```auto
page {
 ...other stuff
  body {
   ... on games_section {
     non-repeat { ...non-repeatFields }
     repeat { ...repeatFields }
   }
 }
}

```

Am I missing something?

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 11, 2021, 6:07pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/7 "2021-03-11T18:07:14Z")

</div>

@Pau Is this something that can be looked into? I'm currently working on a project that needs this capability to fetch empty slices, but errors are thrown when I try to fetch the slice.

---

<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:** [March 11, 2021, 6:08pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/8 "2021-03-11T18:08:41Z")

</div>

Hey, yes of course.

If you prefer, you can send me your Github project and the instructions to run it so I can take a closer look and we can try and resolve it together.

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 11, 2021, 6:13pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/9 "2021-03-11T18:13:13Z")

</div>

It's a private project, but I can send you a zip file if that's possible. Another option is to create a repro, but it will take some time. Let me know which way you prefer 😃.

---

<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:** [March 11, 2021, 6:21pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/10 "2021-03-11T18:21:21Z")

</div>

Whatever is easier for you. I'll send you a dm

---

<div class="post-metadata">

**Author:** ![Levi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/levi/32/24_2.png) [@Levi](https://community.prismic.io/u/Levi)\
**Post date:** [March 24, 2021, 4:04pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/13 "2021-03-24T16:04:58Z")

</div>

Hi @iwatakeshi. Were you able to get this resolved with @Pau? She's off currently, so I'm taking this over. But I am unable to see any private messages between you two, so I'm not sure what the status is here.

---

<div class="post-metadata">

**Author:** ![Levi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/levi/32/24_2.png) [@Levi](https://community.prismic.io/u/Levi)\
**Post date:** [March 24, 2021, 4:54pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/17 "2021-03-24T16:54:55Z")

</div>

@iwatakeshi You can disregard my previous message. I tested this and was able to retrieve an empty slice.

I think the issue in your case might be a slight syntax error. Try removing the space between `...` and `on`:

```auto
page {
  body {
   ...on games_section {
     non-repeat { ...non-repeatFields }
   }
 }
}

```

Let me know if that solves it for you 🙂

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 24, 2021, 7:15pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/22 "2021-03-24T19:15:40Z")

</div>

Hi @Levi! Thank you for the reply.

So I did remove the spaces as suggested, but it still gives me an error 😅.  
I think it does have something to do with the formatting. I'll look into it further. My guess is that the backend doesn't like the extra spaces and new lines. I wished there was a tool that made writing queries easier. Also, maybe a better debugging experience would be nice 😉 . I'll let you guys know if I figure something out.

---

<div class="post-metadata">

**Author:** ![Levi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/levi/32/24_2.png) [@Levi](https://community.prismic.io/u/Levi)\
**Post date:** [March 25, 2021, 2:52pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/23 "2021-03-25T14:52:48Z")

</div>

@iwatakeshi I tried it with your project code and got it to work. The issue is that it didn't like you putting the entire field on one line. I got it to work by moving `...non-repeatFields` and `...repeatFields` to their own lines:

```auto
...on games_section {
  non-repeat {
    ...non-repeatFields
  }
  repeat {
    ...repeatFields
  }
}

```

Give that a try 🙂

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 25, 2021, 3:03pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/24 "2021-03-25T15:03:56Z")

</div>

@Levi That worked! Thank you, Levi!

---

<div class="post-metadata">

**Author:** ![iwatakeshi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/iwatakeshi/32/108_2.png) [@iwatakeshi](https://community.prismic.io/u/iwatakeshi)\
**Post date:** [March 25, 2021, 4:14pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/27 "2021-03-25T16:14:25Z")

</div>

@Levi In case anyone else runs into this issue, I've created a helper function for it:

```auto
function emptySlice(slice: string) {
  return `...on ${slice} {
  non-repeat {
    ...non-repeatFields
  }
  repeat {
    ...repeatFields
  }
}`
}

```

Again, thanks!

---

<div class="post-metadata">

**Author:** ![Levi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/levi/32/24_2.png) [@Levi](https://community.prismic.io/u/Levi)\
**Post date:** [March 25, 2021, 4:25pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/28 "2021-03-25T16:25:44Z")

</div>

That's awesome, thanks for sharing!!

---

<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:** [March 26, 2021, 4:25pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/29 "2021-03-26T16:25:56Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<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:25pm UTC](https://community.prismic.io/t/querying-an-empty-slice-using-graphquery/4424/30 "2021-12-09T16:25:20Z")

</div>


