Skip to content

Commit

Permalink
Added config types from piral-ext #51
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Aug 8, 2019
1 parent c8ce097 commit 4735ee3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 18 additions & 3 deletions src/packages/piral/src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,27 @@ export * from 'piral';
export function renderInstance<TApi = PiletApi, TState extends GlobalState = GlobalState, TActions extends {} = {}>(
options: PiralOptions<TApi, TState, TActions>,
): Promise<EventEmitter> {
const { selector = '#app', gatewayUrl, subscriptionUrl, loader = defaultLoader, config = {}, layout } = options;
const {
selector = '#app',
gatewayUrl,
subscriptionUrl,
loader = defaultLoader,
config = {},
gql = {},
layout,
} = options;
const [AppLayout, initialState] = layout.build();
const load = getLoader(loader, config);
const base = getGateway(gatewayUrl);
const client = setupGqlClient({
url: base,
subscriptionUrl,
...gql,
});
const uri = { base };
const uri = {
base,
...config.fetch,
};
const renderLayout = (content: React.ReactNode) => <AppLayout>{content}</AppLayout>;
const defaultRequestPilets = () => gqlQuery<PiletQueryResult>(client, piletsQuery).then(({ pilets }) => pilets);

Expand All @@ -73,6 +85,8 @@ export function renderInstance<TApi = PiletApi, TState extends GlobalState = Glo
extendApi = defaultExtendApi,
attach,
actions,
fetch: fetchOptions = uri,
locale: localeOptions = config.locale,
state: explicitState,
...forwardOptions
} = {}) => {
Expand All @@ -93,6 +107,7 @@ export function renderInstance<TApi = PiletApi, TState extends GlobalState = Glo
const localizer = setupLocalizer({
language: state.app.language.selected,
messages,
...localeOptions,
});
const Piral = createInstance({
...forwardOptions,
Expand All @@ -104,7 +119,7 @@ export function renderInstance<TApi = PiletApi, TState extends GlobalState = Glo
},
extendApi(api, target) {
const newApi: any = {
...createFetchApi(uri),
...createFetchApi(fetchOptions),
...createGqlApi(client),
...createLocaleApi(localizer),
...api,
Expand Down
21 changes: 14 additions & 7 deletions src/packages/piral/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { ArbiterModuleMetadata } from 'react-arbiter';
import { LocalizationMessages, FetchConfig, GqlConfig, LocaleConfig } from 'piral-ext';
import { PiralStateConfiguration, GlobalState, PiletRequester, Extend } from 'piral-core';
import {
LocalizationMessages,
PiralGqlApiQuery,
PiralFetchApiFetch,
PiralGqlApiMutate,
PiralGqlApiSubscribe,
} from 'piral-ext';
import { PiralGqlApiQuery, PiralFetchApiFetch, PiralGqlApiMutate, PiralGqlApiSubscribe } from 'piral-ext';
import { LayoutBuilder } from './layout';

export interface PiralAttachment<TApi> {
Expand Down Expand Up @@ -40,6 +35,14 @@ export interface PiralConfig<TApi, TState extends GlobalState = GlobalState, TAc
* functionality.
*/
extendApi?: Extend<TApi>;
/**
* Sets up the configuration for fetch.
*/
fetch?: FetchConfig;
/**
* Sets up the configuration for localization.
*/
locale?: LocaleConfig;
}

export interface PiralLoaderOptions {
Expand Down Expand Up @@ -85,4 +88,8 @@ export interface PiralOptions<TApi, TState extends GlobalState = GlobalState, TA
* Gets the layout builder to construct the design to display.
*/
layout: LayoutBuilder;
/**
* Sets up the configuration for GraphQL.
*/
gql?: GqlConfig;
}

0 comments on commit 4735ee3

Please sign in to comment.