mirror of https://github.com/Squidex/squidex.git
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.
48 lines
1.3 KiB
48 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 { of } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import * as React from 'react';
|
|
import * as ReactDOM from 'react-dom';
|
|
|
|
import GraphiQL from 'graphiql';
|
|
|
|
import { AppsState, GraphQlService } from '@app/shared';
|
|
|
|
@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();
|
|
}
|
|
}
|