Skip to content

Commit

Permalink
feat: derived types from function
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvtrinidad authored and lgandecki committed Jul 6, 2021
1 parent 7ecbf2a commit c502eef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/generate/templates/typeTypeResolvers.spec.handlebars
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import td from "testdouble";
import { GqlContext, ParentType, test{{typeName}}{{capitalizedFieldName}} {{#if hasArguments}},{{pascalCasedArgName}}{{/if}} } from "{{generatedPrefix}}/graphql/helpers/{{typeName}}{{capitalizedFieldName}}SpecWrapper"
import { GqlContext, ParentType, test{{typeName}}{{capitalizedFieldName}} {{#if hasArguments}},ArgsType{{/if}} } from "{{generatedPrefix}}/graphql/helpers/{{typeName}}{{capitalizedFieldName}}SpecWrapper"

test("{{typeName}}{{capitalizedFieldName}}", async () => {
const context = td.object<GqlContext>();
// td.when(context.{{moduleName}}Repository.findOne()).thenResolve()
// const parent: ParentType = {}
{{#if hasArguments}}
// const variables: {{pascalCasedArgName}} = {}
// const args: ArgsType = {}
{{/if}}

// const result = await test{{typeName}}{{capitalizedFieldName}}(parent, {{#if hasArguments}}variables,{{/if}} context);
// const result = await test{{typeName}}{{capitalizedFieldName}}(parent, {{#if hasArguments}}args,{{/if}} context);

});
10 changes: 7 additions & 3 deletions src/generate/templates/typeTypeResolversSpecWrapper.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { GraphQLResolveInfo } from 'graphql'
import type { GqlContext, ResolversParentTypes, {{#if hasArguments}}{{pascalCasedArgName}}{{/if}} } from "{{generatedPrefix}}/graphql/types";
import { {{typeName}}{{capitalizedFieldName}} } from "{{appPrefix}}/{{graphqlFileRootPath}}types/{{typeName}}{{capitalizedFieldName}}";

type Params = Parameters<NonNullable<typeof {{typeName}}{{capitalizedFieldName}}>>
{{#if resolveReferenceType}}type ParentType = Parameters<NonNullable<typeof {{typeName}}{{capitalizedFieldName}}>>[0];{{else}}
type ParentType = ResolversParentTypes["{{typeName}}"]
type ParentType = Params[0]
{{/if}}
{{#if hasArguments}}
type ArgsType = Params[1]
{{/if}}

export const test{{typeName}}{{capitalizedFieldName}} = (parent: ParentType, {{#if hasArguments}}variables: {{pascalCasedArgName}},{{/if}} context: GqlContext) => {{typeName}}{{capitalizedFieldName}}?.({...parent, {{#if isFederatedAndExternal}}__typename: '{{typeName}}'{{/if}} }, {{#unless resolveReferenceType}}{{#if hasArguments}}variables{{else}} {} {{/if}},{{/unless}} context, {} as GraphQLResolveInfo)
export const test{{typeName}}{{capitalizedFieldName}} = (parent: ParentType, {{#if hasArguments}}args: ArgsType,{{/if}} context: GqlContext) => {{typeName}}{{capitalizedFieldName}}?.({...parent, {{#if isFederatedAndExternal}}__typename: '{{typeName}}'{{/if}} }, {{#unless resolveReferenceType}}{{#if hasArguments}}args{{else}} {} {{/if}},{{/unless}} context, {} as GraphQLResolveInfo)

export type {GqlContext, ParentType, ResolversParentTypes {{#if hasArguments}},{{pascalCasedArgName}}{{/if}} }
export type {GqlContext, ParentType, ResolversParentTypes {{#if hasArguments}}, ArgsType, {{pascalCasedArgName}}{{/if}} }

0 comments on commit c502eef

Please sign in to comment.