我正在使用GraphQL和Apollo开发Angular应用程序,该应用程序显示来自本地GraphQL API的数据 .

另外,我正在开发一个允许用户将新数据发布到API的表单,但我不确定我是否在这里使用了正确的方法 .

目前我收到此错误:

ERROR TypeError: Converting circular structure to JSON

现在,让我告诉你相关的代码 .

form.component.html

这是访问onSubmit-Function的HTML表单 .

<button type="submit" (click)="onSubmit()" [disabled]="!personForm.valid" id="buttonSubmit" mat-raised-button color="accent"class="floated">Send</button>

form.component.ts

在这里,我使用this.apollo.mutate将新数据订阅到API

onSubmit(formDirective) 
  {
    let surname =  this.personForm.get('surname');
    let name =  this.personForm.get('name');
    let email =  this.personForm.get('email');
    let status =  this.personForm.get('status');
    let activity =  this.personForm.get('activity');

    this.apollo.mutate<CreateUserMutationResponse>({
      mutation: CREATE_USER_MUTATION,
      variables: {
        surname: surname,
        name: name,
        email: email,
        status: status,
        activity: activity
      }
    }).subscribe((response) => {

    });

    console.log('submitted');

  }

types.ts

export type User = {
    surname: string;
    name: string;
    email: string;
    status: string;
    activity: string;
  }

  export type Query = {
      users: User[];
  }

  export const CREATE_USER_MUTATION = gql`
  mutation CreateUserMutation($surname: String!, $name: String!, $email: String!, $status: String!, $activity: String!) {
    createUser(surname: $surname, name: $name, email: $email, status: $status, activity: $activity) {
        surname
        name
        email
        status
        activity
    }
  }
`;

  export interface CreateUserMutationResponse {
    createUser: User;
  }

任何指向正确的方向将非常感谢,谢谢!