@homebound/graphql-typescript-simple-resolvers
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -39,3 +39,5 @@ "use strict"; | ||
})} | ||
${scalars.filter(s => !builtInScalars.includes(s.name)).map(s => { | ||
${scalars | ||
.filter(s => !builtInScalars.includes(s.name)) | ||
.map(s => { | ||
return ts_poet_1.code `${s.name}: ${GraphQLScalarTypeSymbol};`; | ||
@@ -56,9 +58,10 @@ })} | ||
if (f.args.length > 0) { | ||
argDefs.push(ts_poet_1.code `export interface ${argsName} { | ||
${f.args.map(a => ts_poet_1.code `${a.name}: ${mapType(config, a.type)}; `)} | ||
}`); | ||
argDefs.push(ts_poet_1.code ` | ||
export interface ${argsName} { | ||
${f.args.map(a => ts_poet_1.code `${a.name}: ${mapType(config, a.type)}; `)} | ||
}`); | ||
} | ||
const root = mapObjectType(config, type); | ||
const result = mapType(config, f.type); | ||
return ts_poet_1.code `${f.name}(root: ${root}, args: ${args}, ctx: ${ctx}, info: ${GraphQLResolveInfo}): MaybePromise<${result}>;`; | ||
return ts_poet_1.code `${f.name}: Resolver<${root}, ${args}, ${result}>;`; | ||
})} | ||
@@ -68,2 +71,5 @@ } | ||
}); | ||
chunks.push(ts_poet_1.code ` | ||
type Resolver<R, A, T> = (root: R, args: A, ctx: ${ctx}, info: ${GraphQLResolveInfo}) => T | Promise<T>; | ||
`); | ||
argDefs.forEach(a => chunks.push(a)); | ||
@@ -107,6 +113,7 @@ // For the output types with optional resolvers, make DTOs for them | ||
const [path, symbol] = mappedEnum.split("#"); | ||
chunks.push(ts_poet_1.code `export { ${symbol} } from "${path}";`); | ||
chunks.push(ts_poet_1.code ` | ||
export { ${symbol} } from "${path}"; | ||
`); | ||
} | ||
}); | ||
chunks.push(maybePromise); | ||
const content = await ts_poet_1.code `${chunks}`.toStringWithImports(); | ||
@@ -199,4 +206,1 @@ return { content }; | ||
} | ||
const maybePromise = ts_poet_1.code ` | ||
type MaybePromise<T> = T | Promise<T> | ||
`; |
@@ -1,3 +0,3 @@ | ||
import { GraphQLScalarType, GraphQLResolveInfo } from "graphql"; | ||
import { Context, AuthorId, Popularity } from "./entities"; | ||
import { GraphQLResolveInfo, GraphQLScalarType } from "graphql"; | ||
@@ -14,31 +14,29 @@ export interface Resolvers { | ||
export interface QueryResolvers { | ||
authors(root: {}, args: QueryAuthorsArgs, ctx: Context, info: GraphQLResolveInfo): MaybePromise<AuthorId[]>; | ||
authorSummaries(root: {}, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<AuthorSummary[]>; | ||
authors: Resolver<{}, QueryAuthorsArgs, AuthorId[]>; | ||
authorSummaries: Resolver<{}, {}, AuthorSummary[]>; | ||
} | ||
export interface AuthorResolvers { | ||
name(root: AuthorId, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<string>; | ||
summary(root: AuthorId, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<AuthorSummary>; | ||
popularity(root: AuthorId, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<Popularity>; | ||
working(root: AuthorId, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<Working | null>; | ||
birthday(root: AuthorId, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<Date | null>; | ||
name: Resolver<AuthorId, {}, string>; | ||
summary: Resolver<AuthorId, {}, AuthorSummary>; | ||
popularity: Resolver<AuthorId, {}, Popularity>; | ||
working: Resolver<AuthorId, {}, Working | null>; | ||
birthday: Resolver<AuthorId, {}, Date | null>; | ||
} | ||
export interface MutationResolvers { | ||
saveAuthor( | ||
root: {}, | ||
args: MutationSaveAuthorArgs, | ||
ctx: Context, | ||
info: GraphQLResolveInfo, | ||
): MaybePromise<SaveAuthorResult>; | ||
saveAuthor: Resolver<{}, MutationSaveAuthorArgs, SaveAuthorResult>; | ||
} | ||
export interface AuthorSummaryResolvers { | ||
numberOfBooks(root: AuthorSummary, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<number>; | ||
amountOfSales(root: AuthorSummary, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<number | null>; | ||
numberOfBooks: Resolver<AuthorSummary, {}, number>; | ||
amountOfSales: Resolver<AuthorSummary, {}, number | null>; | ||
} | ||
export interface SaveAuthorResultResolvers { | ||
author(root: SaveAuthorResult, args: {}, ctx: Context, info: GraphQLResolveInfo): MaybePromise<AuthorId>; | ||
author: Resolver<SaveAuthorResult, {}, AuthorId>; | ||
} | ||
type Resolver<R, A, T> = (root: R, args: A, ctx: Context, info: GraphQLResolveInfo) => T | Promise<T>; | ||
export interface QueryAuthorsArgs { | ||
@@ -62,3 +60,5 @@ id: string | null; | ||
} | ||
export { Popularity } from "./entities"; | ||
export enum Working { | ||
@@ -68,3 +68,1 @@ Yes = "YES", | ||
} | ||
type MaybePromise<T> = T | Promise<T>; |
{ | ||
"name": "@homebound/graphql-typescript-simple-resolvers", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"main": "./build/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./build/", |
12813
277