Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.3 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
import { AppsState, GraphQlService } from '@app/shared';
import GraphiQL from 'graphiql';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { of } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Component({
selector: 'sqx-graphql-page',
styleUrls: ['./graphql-page.component.scss'],
templateUrl: './graphql-page.component.html'
})
export class GraphQLPageComponent implements AfterViewInit {
@ViewChild('graphiQLContainer', { static: false })
public graphiQLContainer: ElementRef;
constructor(
private readonly appsState: AppsState,
private readonly graphQlService: GraphQlService
) {
}
public ngAfterViewInit() {
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: (params: any) => {
return this.request(params);
}
}),
this.graphiQLContainer.nativeElement
);
}
private request(params: any) {
return this.graphQlService.query(this.appsState.appName, params).pipe(
catchError(response => of(response.error)))
.toPromise();
}
}