-
Notifications
You must be signed in to change notification settings - Fork 22
Creating the interfacing service
Juan Stoppa edited this page Apr 14, 2019
·
18 revisions
Any application that intends to use FormQL needs to implement a service that follows the IFormQLService
signature (in the package @formql/core), this allows FormQL to interact with the form and data and gives the flexibility to use any backend technology.
export interface IFormQLService {
getData(dataSource: FormDataSource, ids: Array<string>): Observable<any>;
getForm(name: string): Observable<FormWindow>;
getForms(): Observable<Array<FormWindow>>;
saveForm(name: string, form: FormWindow): Observable<any>;
saveData(dataSource: FormDataSource, ids: Array<string>, data: any): Observable<any>;
}
In order to let FormQL use the service, the app needs to
- Define the Service in 'NgModule' making sure to link it with the string
'FormQLService'
(see below the lineproviders: [MyAppService, {provide: 'FormQLService', useClass: MyAppService }]
)
import { FormQLModule } from '@formql/core';
import { FormQLEditorModule } from '@formql/editor';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormQLModule,
FormQLEditorModule,
],
providers: [MyAppService, {provide: 'FormQLService', useClass: MyAppService }],
bootstrap: [AppComponent]
})
export class AppModule { }
- Create the service implementing the
IFormQLService
interface. NOTE: TheFormWindow
object used in getForm and getForms is the interface that represents the form, it's advised that you implement the same object in your backend rather than storing it as astring
import { IFormQLService, FormWindow, FormDataSource } from "@formql/core";
@Injectable()
export class MyAppService implements IFormQLService {
constructor(private http: HttpClient) {}
getData(dataSource: FormDataSource, ids: Array<string>): Observable<any> {
// get data implementation
}
getForm(name: string): Observable<FormWindow> {
// get form implementation
}
getForms(): Observable<Array<FormWindow>> {
// get forms implementation ( return a list with all the forms available)
}
saveForm(name: string, form: FormWindow): Observable<FormWindow> {
// save form implementation
}
saveData(dataSource: FormDataSource, ids: Array<string>, data: any): Observable<any> {
// save data implementation
}
}