One-to-many inside graphql

I have a list of testimonials inside a group (using content relationship fields). I have been trying to access the data inside each testimonial within the list.

I realise I have to use GraphQuery but I am struggling to follow the instruction.

This is the JSON structure.

`{
  "Main" : {
  "prismic_title" : {
    "type" : "StructuredText",
    "config" : {
    "single" : "heading6",
    "label" : "Title (only used to name entry in Prismic list)",
    "placeholder" : "This is used only to render a title in Prismic (otherwise we get \"undefined\")"
  }
},
  "page" : {
  "type" : "Select",
  "config" : {
    "options" : [ "Homepage", "Option2", "Option3" ],
    "label" : "Website page to appear on:"
  }
},
  "testimonial_list" : {
  "type" : "Group",
  "config" : {
    "fields" : {
      "testimonial" : {
        "type" : "Link",
        "config" : {
          "select" : "document",
          "customtypes" : [ "testimonial" ],
          "label" : "testimonial"
        }
      }
    },
    "label" : "Testimonial List"
    }
   }
  }
}`

This is the group within the Type:

I have looked into your explanation of the topic:


…and this post:

I’ve tried implementing it this way but I’m not getting the fields expected in graphql.

Any help with this would be much appreciated!

Hi @devaccounts. When using Gatsby with Prismic, there is no need to use the GraphQuery option. GraphQuery is different than the GraphQL API and is meant to be used with the REST API.

In your case, I encourage you to check out our Gatsby documentation. Here specifically is how to retrieve content from linked documents:
https://prismic.io/docs/gatsby/retrieving-prismic-fields/retrieve-links-or-content-relationships#6_1-retrieve-a-content-relationship-field

Hi Levi, thanks for the response.
Okay, that makes more sense. Your page on One-to-many relationships tells us GraphQuery is the way to get content from groups, then links to GraphQuery - a little confusing.
Thanks for the link. I’ll look into it.

@devaccounts I’m glad that it makes more sense now. I’ll look at the One-to-many article and see if I can make it more clear that GraphQuery is only needed for the Rest API.

I mean it makes sense, just didnt read that way. :slight_smile:

I am using the gatsby-source-prismic plugin as opposed to the gatsby-source-prismic-graphql.

Is this functionality still available to me using this plugin? I see on the example it uses the alternate plugin.

@devaccounts You’re correct that our documentation and examples all use the gatsby-source-prismic-graphql plugin.

But I took a quick look at the gatsby-source-prismic README and it looks like this is how to retrieve content from linked documents.

1 Like

The clue is in the name :upside_down_face:

Cheers mate, big help.

1 Like

@levi Following the page you linked I have navigated to where the testimonial content fields are being held and returns the correct amount of nodes, but my document returns null, is there a step I’m missing in order to populate the document field?

The query:

Can you send me the url for your repository? You can either send it here or in a private message to me.

@devaccounts So I took a look and can’t see what the issue might be. From the little I know about this plugin, your query looks right to me.

The only thing I can think of would be to run gatsby clean and rebuild the gatsby site. If that doesn’t work, then maybe you can submit an issue via the plugin’s github issue page.

I have done both of those options more than once, but thank you for trying.
I guess it’ll have to be a post on the plugin. Cheers anyway.

Hi @devaccounts

The first thing I can think of is that the schemas are no up to date.

For anything else I will need to investigate further to assist with this process a I will need a project that recreates the issue, and details about the prismic repository you are using.

So if updating the schemas doesn’t work let me know and we’ll start debugging the issue. :slight_smile:

Hello, I’ve double checked the schema and it is up to date.

Is there anything I can do to help us work through this?

Hi @devaccounts
Yes, providing a recreation of the issue on github would help me debug the issue :slight_smile: