为什么 apollo-angular 查询返回空数组?

Why is apollo-angular Query returning empty array?

我最近安装并设置了 apollo-angular,但无法从查询中获取数据。我提到了处理类似问题的 ,但它们没有帮助。我可以确定的是:

我希望从此查询中获取字符串值,并且当我记录响应数据的结果时,我得到的只是一个带有 table 名称的空数组标签。组件代码:

import { Component, OnInit, OnDestroy } from '@angular/core';

import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag';

const getGoal = gql`
  query GetGoal($survey_id: String!) {
    goals(where: { survey_id: { _eq: $survey_id } }) {
      survey_id
      goal
    }
  }
`;

@Component({
  selector: 'app-goals',
  templateUrl: './goals.component.html',
  styleUrls: ['./goals.component.css']
})
export class GoalsComponent implements OnInit {
  loading: boolean;
  goal: any;

  constructor(private apollo: Apollo) {}

  ngOnInit() {
    this.apollo
      .watchQuery<any>({
        query: getGoal,
        variables: {
          survey_id: 'test_survey'
        }
      })
      .valueChanges.subscribe(({ data, loading }) => {
        this.loading = loading;
        this.goal = data.goals.goal;
      });
  }
}

这里的问题是权限配置不正确,所以如果您遇到类似问题,请检查您的权限,确保嵌套表正确连接等:我没有太多处理嵌套权限,所以我不不知道是否有更有效的方法来解决这个问题,但是在我查询的表中添加一个 user_id 字段,并添加标准的“user_id _eq x-hasura-user-id”约束修复了问题。