Configuration
The sdr
cli looks for a sfc.yml
config file at the root of your projects directory. It will look something like this:
schema: ./schema/*.graphql # the schemas you want to act onprettier: ./.prettierrc # an optional prettier file for js/ts filesconfig: @sdr/raw-fetch: # config values for the plugins baseClientLocation: ./baseClientgenerates: api/api.ts: # the name of the file to generate plugins: # the plugins to use on this file - @sdr/raw-fetch - @sdr/models
The above sfc.yml
file will create a file named api/api.ts
that will contain the output from the @sdr/raw-fetch and @sdr/models plugins. The output will look something like:
/* This file was generated by https://github.com/schema-driven-rest/plugin-raw-fetch *//* tslint:disable */import {BaseClient, ControllerOptions} from './baseClient';
export class UserClient extends BaseClient { constructor(options: ControllerOptions) { super(options); }
async login(model: LoginRequest): Promise<LoginResponse> { try { let url = this.options.baseUrl + '/user/login?'; const options = { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, } as RequestInit;
options.body = JSON.stringify(model);
const response = await fetch(url, await this.transformOptions(options));
const status = response.status; const headers: any = {};
if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => (headers[k] = v)); }
const responseText = await response.text();
if (status === 200) { return JSON.parse(responseText); } else { try { const body = JSON.parse(responseText); throw body; } catch (ex) { throw ex; } } } catch (ex) { throw ex; } }}
export type Maybe<T> = T | null;type FixDecorator<T> = T; /** All built-in and custom scalars, mapped to their actual values */export type Scalars = { ID: string; String: string; Boolean: boolean; Int: number; Float: number;};
export class LoginResponse { authorized!: Scalars['Boolean']; jwt!: Scalars['String'];}
export class LoginRequest { username!: Scalars['String'];}