Skip to content

Commit 603331f

Browse files
authored
Merge pull request feathersjs-ecosystem#481 from NickBolles/njb/fix-fgraphql-types
update names and fix the options property
2 parents b4d2cf3 + 689b987 commit 603331f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

types/index.d.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Hook, HookContext, Params, Query, Paginated, Application } from '@feathersjs/feathers';
44
import * as ajv from 'ajv';
5-
import { GraphQLSchema, parse } from 'graphql';
5+
import { GraphQLSchema, parse, GraphQLFieldResolver } from 'graphql';
66
import * as libphonenumberjs from 'libphonenumber-js';
77

88
export type HookType = 'before' | 'after' | 'error';
@@ -212,28 +212,32 @@ export interface ResolverMap<T> {
212212
*/
213213
export function fastJoin(resolvers: ResolverMap<any> | SyncContextFunction<ResolverMap<any>>, query?: Query | SyncContextFunction<Query>): Hook;
214214

215-
export type ResolversFunction = (app: Application, runtime: any) => ResolversObject;
215+
export type FGraphQLResolverMapFactory = (app: Application, runtime: any) => FGraphQLResolverMap;
216216

217-
export interface ResolversObject {
217+
export interface FGraphQLResolverMap {
218218
[i: string]: {
219-
[i: string]: (parent: any, args: any, content: any, ast: any) => any;
219+
[i: string]: GraphQLFieldResolver<any, any>
220220
};
221221
Query: {
222-
[i: string]: (parent: any, args: any, content: any, ast: any) => any;
222+
[i: string]: GraphQLFieldResolver<any, any>
223223
};
224224
}
225225

226-
export interface FGraphqlOptions {
227-
recordType: string;
228-
schema: string;
229-
resolvers: ResolversObject | ResolversFunction;
230-
query: Query | SyncContextFunction<Query>;
226+
export interface FGraphQLOptions {
231227
skipHookWhen?: SyncContextFunction<boolean>;
232228
inclAllFieldsServer?: boolean;
233229
inclAllFieldsClient?: boolean;
234230
inclAllFields?: boolean;
235231
inclJoinedNames?: boolean;
236232
extraAuthProps?: string[];
233+
}
234+
235+
export interface FGraphQLHookOptions {
236+
recordType: string;
237+
schema: string;
238+
resolvers: FGraphQLResolverMap | FGraphQLResolverMapFactory;
239+
query: Query | SyncContextFunction<Query>;
240+
options?: FGraphQLOptions;
237241
runTime: any;
238242
parse: typeof parse;
239243
}
@@ -242,7 +246,7 @@ export interface FGraphqlOptions {
242246
* Generate Graphql Resolvers for services
243247
* {@link https://medium.com/@eddyystop/38faee75dd1}
244248
*/
245-
export function fgraphql(options?: FGraphqlOptions): Hook;
249+
export function fgraphql(options?: FGraphQLHookOptions): Hook;
246250

247251
/**
248252
* Return a property value from an object using dot notation, e.g. address.city. (Utility function.)

types/tests.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
validate,
6464
validateSchema,
6565
when,
66-
FGraphqlOptions,
66+
FGraphQLHookOptions,
6767
} from 'feathers-hooks-common';
6868
import ajv = require('ajv');
6969
import { parse } from 'graphql';
@@ -219,7 +219,7 @@ fastJoin(ctx => postResolvers);
219219
fastJoin(postResolvers);
220220

221221
// used from https://github.com/feathers-plus/hooks-graphql-example
222-
const fgraphqlOptions: FGraphqlOptions = {
222+
const fgraphqlOptions: FGraphQLHookOptions = {
223223
parse,
224224
runTime: null,
225225
schema: ``,
@@ -242,7 +242,7 @@ const fgraphqlOptions: FGraphqlOptions = {
242242
// $ExpectType Hook
243243
fgraphql(fgraphqlOptions);
244244

245-
const fgraphqlOptions2: FGraphqlOptions = {
245+
const fgraphqlOptions2: FGraphQLHookOptions = {
246246
...fgraphqlOptions,
247247
query: (context: HookContext) => ({
248248
posts: {},
@@ -257,6 +257,14 @@ const fgraphqlOptions2: FGraphqlOptions = {
257257
likes: () => ({}),
258258
},
259259
Query: {}
260+
},
261+
options: {
262+
extraAuthProps: ['asdf' ],
263+
inclAllFields: false,
264+
inclJoinedNames: false,
265+
inclAllFieldsClient: true,
266+
inclAllFieldsServer: true,
267+
skipHookWhen: (context) => { context.data; return false; }
260268
}
261269
};
262270
// $ExpectType Hook

0 commit comments

Comments
 (0)