Error message: "Missing attribute X in the GraphQL result for Vue"

Recently started using vue as a frontend with vue 2.3.11 and Django 3 as the backend, connecting them through Apollo via vue-cli.

In my backend, I have a table named documents which consists of only a name and an id field. I am fetching this data from the backend through GraphQL to display a list of names. However, I encountered an error on the console stating

Missing docList attribute on result
.

Below is the HTML template for the Vue file:

<template>
  <div>
    <h2>All the docs</h2>
    <ul v-for="document in docList" :key="document.id">
        <li>
            <strong>{{ document.name }}</strong>
        </li>
    </ul>
  </div>
</template>

Here's the script section of the Vue file containing the tested GraphQL query:

<script>
//Graphql query
import gql from "graphql-tag"

const docList = gql`
query docList {
    documents{
          id,
          name
    }
  }
 `;


export default {
  data() {
    return {
     docList:[],
    };
  },
  apollo: {
    docList:{
      query: docList
    },
  }
};
</script>

This is the output displayed in the browser:

https://i.sstatic.net/l8BIi.jpg

I researched similar errors which were related to naming issues or data mismatch. Despite my attempts to modify the code, I'm still struggling to identify the root cause of the issue.

Answer №1

const documentList = gql`
  query documentList {    // documentList is the query identifier
    documents{       // 'root' of requested data tree structure
      id,
      name
    }
  }
`;

The list starts with documents (an array of document nodes), not with docsList (this identifier is not present in the output).

<ul v-for="document in documents" :key="document.id">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The JSON response is not being returned by the static React App hosted on Microsoft

Seeking assistance from anyone who may have faced and resolved a similar issue. Our React application is deployed on Azure Static Web App and operates smoothly, but we are stuck on configuring it to return JSON instead of HTML in its responses. Within our ...

When trying to log the parsed JSON, it unexpectedly returns undefined even though it appears to be in good

Everything was working fine until a couple of days ago. Let's consider this as my PHP script: echo json_encode(array('stat'=>'ok')); I am sending an AJAX request to this script: $.post(base_url+'line/finalize/', {t ...

To successfully process this file type in JavaScript, you might require a suitable loader

Currently, I am facing an issue with my MVC application while trying to integrate Bootstrap 5 using Webpack. Despite attempting various workarounds with stage-0, stage-2, and stage-3, none have proven successful for me. I suspect that the problem lies wit ...

Eliminating the Skewed Appearance of Text in Input Fields Using CSS

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Customized Page Layout</title> <script src="https://c ...

Utilizing Ajax looping to generate dynamic HTML content with Bootstrap tabs

I am looking for a way to fetch multiple JSON files and display the data from each file in separate Bootstrap 3 Tabs. I understand that the getJSON function does not wait for completion before moving on, but I need help with using callbacks in situations ...

How to run a PHP script using JavaScript?

I am planning to execute a quick php script once users exit my website. Moreover, I am looking to transfer a variable from my javascript to php, but I am unsure how to integrate the php file and pass it a variable. Unfortunately, the php script is not runn ...

Performing an Axios POST request in a React Native and React app using JSON.stringify and Blob functionality

I am currently developing an application where I have encountered an issue when calling an API endpoint in react native. Interestingly, the web app (built with React) does not encounter any errors. Here is the code for the web app using React with TypeScri ...

I need to know the right way to send a file encoded in Windows-1255 using Express

I'm currently developing an API that is responsible for generating text files. The purpose of this API is to support legacy software that specifically requires the use of Windows 1255 encoding for these files. To create the content of the file, I am r ...

Instead of presenting MySQL data in tables on an HTML page, showcase it in editable text boxes

I have successfully imported data from my database table into an HTML table, but now I want to display them in locked text boxes. When the user clicks an "edit" button, the corresponding text box should become unlocked so that they can edit the data and sa ...

How to ensure jQuery runs only once, even when the back button is pressed in the

How can I ensure that jQuery only executes once, even when navigating back to the page using the browser's back button? When my page initially loads, the jQuery runs fine. However, if I navigate away from the page and then return using the back button ...

Tips for personalizing the appearance of active bootstrap tabs?

I am currently working on creating a website where Bootstrap tabs will display content according to their unique ID when selected. However, I have encountered an issue where the tab selected does not remain active. I am thinking of creating a custom active ...

Exploring Vue 3's Methods for Sending Data to Vuex Store within the Setup Phase

I'm currently working on a project that involves Vue 3 and Vuex. This is my first time using Vue 3, and I'm having trouble accessing Vuex within the Setup method of my Vue 3 project. Specifically, I have a feature object that is set by a Childco ...

I encountered a data discrepancy while attempting to link up with a weather API

This is my debut app venture utilizing node.js and express for the first time. The concept behind this basic application involves connecting to an external API to retrieve temperature data, while also allowing users to input their zip code and feelings whi ...

Selecting the correct filter method for handling extensive arrays: Comparing REST and Local Array techniques

What is the optimal approach for an application designed to filter a large amount of data, such as 5000+ records, while prioritizing response speed? Filtering local memory arrays Querying the database through HTTP API request calls In my app, I utilize A ...

Steps for passing a Javascript variable through POST method and then redirecting to a different page

I am facing an issue with sending a JavaScript variable via POST to a PHP page and displaying the new page. Despite checking the variable using Wireshark and confirming that it is sent correctly (key and value), the new page does not show anything. $(docu ...

Guide to updating the favicon with next js

I am facing an issue where the favicon is not changing when searched on Google. The image is located in the public folder, but it is still showing the old logo instead of the new one. Below is the code from the _document.tsx file: <Html dir={dir}> ...

VueJS Error: Attempting to access a property that is undefined causing a TypeError (reading 'toLowerCase')

Whenever I attempt to filter and remove items from an array, everything works fine. However, when I try to add new items to the array, I encounter an error message that says "TypeError: Cannot read properties of undefined (reading 'toLowerCase'). ...

Tips for utilizing JSON.parse

Within my ajax request, I am encountering the following code: 403: function(jqXHR) { var error = jqXHR.responseText; console.log(error); } When this error occurs, a message is displayed in the console: Htt ...

Angular - Strategies for Handling Observables within a Component

I am new to Angular and recently started learning how to manage state centrally using ngRx. However, I am facing a challenge as I have never used an Observable before. In my code, I have a cart that holds an array of objects. My goal is to iterate over the ...

What is the best way to make the first <p> tags bold within an array?

I tried using ::first-line, but it bolds all the p tags in the array. What I want is to only bold the first p tag which contains "Hello". https://i.sstatic.net/l0Ss6.png <div v-for="item in first" :key="item.id"> <p cl ...