Skip to content

Commit 83cf73d

Browse files
Fix support for resolvers on input types in single file mode in the resolver plugin (#8)
1 parent d83cd09 commit 83cf73d

File tree

21 files changed

+104
-1
lines changed

21 files changed

+104
-1
lines changed

codegen/testserver/followschema/resolver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ func (r *wrappedSliceResolver) Get(ctx context.Context, obj WrappedSlice, idx in
537537
panic("not implemented")
538538
}
539539

540+
// OverrideFirstField is the resolver for the overrideFirstField field.
541+
func (r *fieldsOrderInputResolver) OverrideFirstField(ctx context.Context, obj *FieldsOrderInput, data *string) error {
542+
panic("not implemented")
543+
}
544+
540545
// BackedByInterface returns BackedByInterfaceResolver implementation.
541546
func (r *Resolver) BackedByInterface() BackedByInterfaceResolver {
542547
return &backedByInterfaceResolver{r}
@@ -589,6 +594,9 @@ func (r *Resolver) WrappedMap() WrappedMapResolver { return &wrappedMapResolver{
589594
// WrappedSlice returns WrappedSliceResolver implementation.
590595
func (r *Resolver) WrappedSlice() WrappedSliceResolver { return &wrappedSliceResolver{r} }
591596

597+
// FieldsOrderInput returns FieldsOrderInputResolver implementation.
598+
func (r *Resolver) FieldsOrderInput() FieldsOrderInputResolver { return &fieldsOrderInputResolver{r} }
599+
592600
type backedByInterfaceResolver struct{ *Resolver }
593601
type deferModelResolver struct{ *Resolver }
594602
type errorsResolver struct{ *Resolver }
@@ -605,3 +613,4 @@ type subscriptionResolver struct{ *Resolver }
605613
type userResolver struct{ *Resolver }
606614
type wrappedMapResolver struct{ *Resolver }
607615
type wrappedSliceResolver struct{ *Resolver }
616+
type fieldsOrderInputResolver struct{ *Resolver }

codegen/testserver/singlefile/resolver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ func (r *wrappedSliceResolver) Get(ctx context.Context, obj WrappedSlice, idx in
537537
panic("not implemented")
538538
}
539539

540+
// OverrideFirstField is the resolver for the overrideFirstField field.
541+
func (r *fieldsOrderInputResolver) OverrideFirstField(ctx context.Context, obj *FieldsOrderInput, data *string) error {
542+
panic("not implemented")
543+
}
544+
540545
// BackedByInterface returns BackedByInterfaceResolver implementation.
541546
func (r *Resolver) BackedByInterface() BackedByInterfaceResolver {
542547
return &backedByInterfaceResolver{r}
@@ -589,6 +594,9 @@ func (r *Resolver) WrappedMap() WrappedMapResolver { return &wrappedMapResolver{
589594
// WrappedSlice returns WrappedSliceResolver implementation.
590595
func (r *Resolver) WrappedSlice() WrappedSliceResolver { return &wrappedSliceResolver{r} }
591596

597+
// FieldsOrderInput returns FieldsOrderInputResolver implementation.
598+
func (r *Resolver) FieldsOrderInput() FieldsOrderInputResolver { return &fieldsOrderInputResolver{r} }
599+
592600
type backedByInterfaceResolver struct{ *Resolver }
593601
type deferModelResolver struct{ *Resolver }
594602
type errorsResolver struct{ *Resolver }
@@ -605,3 +613,4 @@ type subscriptionResolver struct{ *Resolver }
605613
type userResolver struct{ *Resolver }
606614
type wrappedMapResolver struct{ *Resolver }
607615
type wrappedSliceResolver struct{ *Resolver }
616+
type fieldsOrderInputResolver struct{ *Resolver }

plugin/resolvergen/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (m *Plugin) generateSingleFile(data *codegen.Data) error {
6666
return err
6767
}
6868

69-
for _, o := range data.Objects {
69+
for _, o := range append(data.Objects, data.Inputs...) {
7070
if o.HasResolvers() {
7171
caser := cases.Title(language.English, cases.NoLower)
7272
rewriter.MarkStructCopied(templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type))

plugin/resolvergen/resolver_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func TestLayoutSingleFile(t *testing.T) {
2626
require.NoError(t, err)
2727

2828
require.NoError(t, p.GenerateCode(data))
29+
30+
b, err := os.ReadFile("testdata/singlefile/out/resolver.go")
31+
require.NoError(t, err)
32+
source := string(b)
33+
require.Contains(t, source, "func (r *CustomResolverType) Query() QueryResolver { return &queryCustomResolverType{r} }")
34+
require.Contains(t, source, "func (r *testInputCustomResolverType) InputName(ctx context.Context, obj *TestInput, data string) error {")
35+
2936
assertNoErrors(t, "github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out")
3037
}
3138

plugin/resolvergen/testdata/filetemplate/gqlgen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ resolver:
1414
models:
1515
Resolver:
1616
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.Resolver
17+
TestInput:
18+
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.TestInput
1719

1820
omit_gqlgen_version_in_file_notice: true

plugin/resolvergen/testdata/filetemplate/out/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package customresolver
33
import "context"
44

55
type Resolver struct{}
6+
type TestInput struct{}
67

78
type QueryResolver interface {
89
Resolver(ctx context.Context) (*Resolver, error)
@@ -11,3 +12,6 @@ type QueryResolver interface {
1112
type ResolverResolver interface {
1213
Name(ctx context.Context, obj *Resolver) (string, error)
1314
}
15+
type TestInputResolver interface {
16+
InputName(ctx context.Context, obj *TestInput, data string) error
17+
}

plugin/resolvergen/testdata/followschema/gqlgen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ resolver:
1313
models:
1414
Resolver:
1515
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.Resolver
16+
TestInput:
17+
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.TestInput
1618

1719
omit_gqlgen_version_in_file_notice: true

plugin/resolvergen/testdata/followschema/out/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package customresolver
33
import "context"
44

55
type Resolver struct{}
6+
type TestInput struct{}
67

78
type QueryResolver interface {
89
Resolver(ctx context.Context) (*Resolver, error)
@@ -11,3 +12,6 @@ type QueryResolver interface {
1112
type ResolverResolver interface {
1213
Name(ctx context.Context, obj *Resolver) (string, error)
1314
}
15+
type TestInputResolver interface {
16+
InputName(ctx context.Context, obj *TestInput, data string) error
17+
}

plugin/resolvergen/testdata/omit_template_comment/gqlgen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ resolver:
1414
models:
1515
Resolver:
1616
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.Resolver
17+
TestInput:
18+
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.TestInput
1719

1820
omit_gqlgen_version_in_file_notice: true

plugin/resolvergen/testdata/omit_template_comment/out/schema.resolvers.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)