Skip to content

Commit

Permalink
Added schema SDL action.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed May 10, 2019
1 parent d228f43 commit 31e7cfe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app/actions/gql-schema/gql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const SET_INTROSPECTION = 'SET_INTROSPECTION';
export const SET_INTROSPECTION_FROM_DB = 'SET_INTROSPECTION_FROM_DB';

export const SET_SCHEMA = 'SET_SCHEMA';
export const SET_SCHEMA_SDL = 'SET_SCHEMA_SDL';
export const SET_ALLOW_INTROSPECTION = 'SET_ALLOW_INTROSPECTION';

export const EXPORT_SDL = 'EXPORT_SDL';
Expand All @@ -27,6 +28,12 @@ export class SetSchemaAction implements Action {
constructor(public windowId: string, public payload: any) { }
}

export class SetSchemaSDLAction implements Action {
readonly type = SET_SCHEMA_SDL;

constructor(public windowId: string, public payload: { sdl: string }) { }
}

export class SetAllowIntrospectionAction implements Action {
readonly type = SET_ALLOW_INTROSPECTION;

Expand All @@ -49,6 +56,7 @@ export type Action =
| SetIntrospectionAction
| SetIntrospectionFromDbAction
| SetSchemaAction
| SetSchemaSDLAction
| SetAllowIntrospectionAction
| ExportSDLAction
| LoadSDLSchemaAction
Expand Down
17 changes: 17 additions & 0 deletions src/app/effects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ export class QueryEffects {
return observableEmpty();
}));

// Sets the schema SDL after setting the schema
@Effect()
setSchemaSDL$: Observable<Action> = this.actions$
.ofType(gqlSchemaActions.SET_SCHEMA)
.pipe(
switchMap((action: gqlSchemaActions.SetSchemaAction) => {
const schema = action.payload;
if (schema) {
return observableOf(
new gqlSchemaActions.SetSchemaSDLAction(action.windowId, { sdl: this.gqlService.getSDL(schema) })
);
}

return observableEmpty();
})
);

@Effect()
loadSDLSchema$: Observable<Action> = this.actions$
.ofType(gqlSchemaActions.LOAD_SDL_SCHEMA)
Expand Down
10 changes: 7 additions & 3 deletions src/app/reducers/gql-schema/gql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ import * as gqlSchema from '../../actions/gql-schema/gql-schema';
export interface State {
introspection: object;
schema: object;
sdl: string;
allowIntrospection: boolean;
}

export const initialState: State = {
introspection: null,
schema: null,
sdl: '',
allowIntrospection: true
};

export function gqlSchemaReducer(state = initialState, action: gqlSchema.Action): State {
switch (action.type) {
case gqlSchema.SET_INTROSPECTION:
case gqlSchema.SET_INTROSPECTION_FROM_DB:
return Object.assign({}, state, { introspection: action.payload });
return { ...state, introspection: action.payload };
case gqlSchema.SET_SCHEMA:
return Object.assign({}, state, { schema: action.payload });
return { ...state, schema: action.payload };
case gqlSchema.SET_ALLOW_INTROSPECTION:
return Object.assign({}, state, { allowIntrospection: action.payload });
return { ...state, allowIntrospection: action.payload };
case gqlSchema.SET_SCHEMA_SDL:
return { ...state, sdl: action.payload.sdl };
default:
return state;
}
Expand Down

0 comments on commit 31e7cfe

Please sign in to comment.