# Need help with graph query and returning fields

**URL:** <https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413>\
**Category:** Developing with Prismic\
**Tags:** graphquery, fetch-linked-content\
**Created:** [July 27, 2024, 1:58pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413 "2024-07-27T13:58:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [July 27, 2024, 1:58pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/1 "2024-07-27T13:58:35Z")

</div>

I have a document that looks like this:

```auto
{
        "id": "YVFtzxEAACMAUusa",
        "uid": "abcde",        
        "first_publication_date": "2021-09-27T07:08:03+0000",
        "last_publication_date": "2022-08-16T15:04:20+0000",
        "data": {            
            "specialisations": [
                {
                    "specialization": {
                        "id": "Ye2kTxMAACMAfe9X",
                        "type": "specialisation",
                        "tags": [],
                        "lang": "ro",
                        "slug": "-",
                        "first_publication_date": "2022-01-23T18:54:13+0000",
                        "last_publication_date": "2024-03-06T13:09:27+0000",
                        "uid": "specialization-one",
                        "link_type": "Document",
                        "isBroken": false
                    }
                }
            ]            
        }
    }    

```

As you can see, my document called "helper" contains a group field, called "specialisations", and in each group field I have a field called "specialization" (notice the "z") which is a link to another document of type "specialisation.

I am now using `graphQuery` in order to obtain the fields, and here is how I am using it:

```auto
const helpers = await client.getAllByType("helper", {
    graphQuery: `{
      helpers {
        specialisations {
          specialization {
            ...on specialisation {
              ...specialisationFields
            }
          }
        }
      }
    }`,
  });

```

No matter how I try I don't get the related document fields. This is how the console log looks like:

```auto
"specialisations": [
                {
                    "specialization": {
                        "id": "Ye2kTxMAACMAfe9X",
                        "type": "specialisation",
                        "tags": [],
                        "lang": "ro",
                        "slug": "-",
                        "first_publication_date": "2022-01-23T18:54:13+0000",
                        "last_publication_date": "2024-03-06T13:09:27+0000",
                        "uid": "cardiologie-interventionala",
                        "link_type": "Document",
                        "isBroken": false
                    }
                }
            ]

```

As you can see the "data" property is missing....

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 27, 2024, 4:04pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/2 "2024-07-27T16:04:30Z")

</div>

Hi there @tudor2004

I believe your close. Here's an example where I grab a content relationship but all I want is the title of the related item. I believe you'll need to replace ...specializationFields with the fields you actually want.

```auto
graphQuery: `
    {
      gallery_item {
        related_content {
          ...on portfolio {
            title
          }
        }
        gallery_image
      }
    }
    `

```

```auto
const helpers = await client.getAllByType("helper", {
    graphQuery: `{
      helpers {
        specialisations {
          specialization {
            ...on specialization {
              title
              richtext // or whatever your fields are
            }
          }
        }
      }
    }`,
  });

```

Give that a shot and let me (us) know how it goes.

---

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [July 27, 2024, 8:19pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/3 "2024-07-27T20:19:16Z")

</div>

Unfortunately it does not work. This is how it looks like right now:

```auto
const helpers = await client.getAllByType("helper", {
    graphQuery: `{
      helpers {
        specialisations {
          specialization {
            ...on specialization {
              title
              position
            }
          }
        }
      }
    }`,
  });

```

And the response looks like this:

```auto
[
    {        
        ...
        "data": {
            ...
            "specialisations": [
                {
                    "specialization": {
                        "id": "Ye2kTxMAACMAfe9X",
                        "type": "specialisation",
                        "tags": [],
                        "lang": "ro",
                        "slug": "-",
                        "first_publication_date": "2022-01-23T18:54:13+0000",
                        "last_publication_date": "2024-03-06T13:09:27+0000",
                        "uid": "my-uid,
                        "link_type": "Document",
                        "isBroken": false
                    }
                }
            ]
            ....
        }
     }
]
```

---

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [July 27, 2024, 8:26pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/4 "2024-07-27T20:26:23Z")

</div>

This is how it looks like when I am using `fetchLinks instead of graphQuery:

```auto
"specialisations": [
                {
                    "specialization": {
                        "id": "Ye2kTxMAACMAfe9X",
                        "type": "specialisation",
                        "tags": [],
                        "lang": "ro",
                        "slug": "-",
                        "first_publication_date": "2022-01-23T18:54:13+0000",
                        "last_publication_date": "2024-03-06T13:09:27+0000",
                        "uid": "my-specialisation",
                        "data": {
                            "title": [
                                {
                                    "type": "heading1",
                                    "text": "My Specialisation",
                                    "spans": []
                                }
                            ],
                            "position": 2
                        },
                        "link_type": "Document",
                        "isBroken": false
                    }
                }
            ],

```

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 27, 2024, 10:18pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/5 "2024-07-27T22:18:42Z")

</div>

Hi there @tudor2004

I made a spelling change that may have impacted your results. I believe we differ in our UK/US English spelling of specialization. Please try this:

```auto
const helpers = await client.getAllByType("helper", {
    graphQuery: `{
      helpers {
        specialisations {
          specialization {
            ...on specialisation {
              title
              position
            }
          }
        }
      }
    }`,
  });

```

Often, when I make an error in my graphQuery, there's an error output in my development console. Are you seeing anything in there if this doesn't work?

---

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [August 12, 2024, 6:20pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/6 "2024-08-12T18:20:51Z")

</div>

Hi and sorry for my late reply.

I have another example, much more simpler, where the graph query still doesn't work:

```auto
const newsItem = await client
    .getByUID("news", uid, {
      graphQuery: `{
        news_item {
          author {
            ...on team_member {
              name
            }
          }
        }
      }`,
    })
    .catch(() => notFound());

console.log("newsItem", newsItem.data.author);

```

Running the script above is returning me something like this:

```auto
newsItem {
  id: 'Zn1LcREAACwAc9ia',
  type: 'team_member',
  tags: [],
  lang: 'ro',
  slug: 'john-doe',
  first_publication_date: '2024-06-27T11:22:28+0000',
  last_publication_date: '2024-07-02T07:33:06+0000',
  uid: 'john-doe',
  link_type: 'Document',
  isBroken: false
}

```

If I am trying the same using `fetchLinks:

```auto
const newsItem = await client
    .getByUID("news", uid, {
      fetchLinks: ["team_member.name"],
    })
    .catch(() => notFound());

```

...I get the following output:

```auto
newsItem {
  id: 'Zn1LcREAACwAc9ia',
  type: 'team_member',
  tags: [],
  lang: 'ro',
  slug: 'john-doe',
  first_publication_date: '2024-06-27T11:22:28+0000',
  last_publication_date: '2024-07-02T07:33:06+0000',
  uid: 'john-doe,
  data: { name: [[Object] ] },
  link_type: 'Document',
  isBroken: false
}

```

I really don't understand what I'm doing wrong with such a basic query.

---

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [August 12, 2024, 6:24pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/7 "2024-08-12T18:24:46Z")

</div>

Ah... my custom type is called `news` not `news_item` 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![tudor2004](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tudor2004](https://community.prismic.io/u/tudor2004)\
**Post date:** [August 12, 2024, 6:30pm UTC](https://community.prismic.io/t/need-help-with-graph-query-and-returning-fields/16413/8 "2024-08-12T18:30:29Z")

</div>

@nf_mastroianni I've read carefully also your last reply and it seems to work now. Thanks very much for your help and patience!
