Angular Apollo 客户端返回错误请求
Angular Apollo client returning bad request
我正在为 Angular 练习 Graphql
& Apollo Client
。
我在从客户端创建查询时遇到问题。
我已经在后端成功创建了 graphql 查询。
下面是我的 GQL 查询,其中 returns 数据显示在 Playground
中
GQL 查询
{
getData {
data {
type
}
}
我的客户端代码,
Service.ts
export class ContentService {
constructor( private apollo: Apollo,
) {
this.getContent();
}
async getContent(): Promise<any> {
const response: any = await this.apollo.query({query: getContentQuery}).toPromise();
return console.log(response);
}
}
请告诉我这里哪里做错了。
无法找到解决方案答案。请帮忙。
所以,这是您在客户端的查询:
import gql from 'graphql-tag';
export const getContentQuery = gql`
query getContent {
metadata {
type
}
}
query getContent
是您在代码中为查询提供的名称,但它并不是要发送到后端的实际 "query name"。
我认为您必须执行以下操作:
import gql from 'graphql-tag';
export const getContentQuery = gql`
query getContent {
getContent {
metadata {
type
}
}
}
我正在为 Angular 练习 Graphql
& Apollo Client
。
我在从客户端创建查询时遇到问题。
我已经在后端成功创建了 graphql 查询。
下面是我的 GQL 查询,其中 returns 数据显示在 Playground
GQL 查询
{
getData {
data {
type
}
}
我的客户端代码,
Service.ts
export class ContentService {
constructor( private apollo: Apollo,
) {
this.getContent();
}
async getContent(): Promise<any> {
const response: any = await this.apollo.query({query: getContentQuery}).toPromise();
return console.log(response);
}
}
请告诉我这里哪里做错了。
无法找到解决方案答案。请帮忙。
所以,这是您在客户端的查询:
import gql from 'graphql-tag';
export const getContentQuery = gql`
query getContent {
metadata {
type
}
}
query getContent
是您在代码中为查询提供的名称,但它并不是要发送到后端的实际 "query name"。
我认为您必须执行以下操作:
import gql from 'graphql-tag';
export const getContentQuery = gql`
query getContent {
getContent {
metadata {
type
}
}
}