diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index 42e84b65da..ae1da002e8 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -96,10 +96,22 @@ resolvers ResolverRoot directives DirectiveRoot complexity ComplexityRoot + sources []*ast.Source + afterUnmarshal []func(ctx context.Context, obj interface{}, value interface{}) error } + func (es *executableSchema) afterUnmarshalInput(ctx context.Context, obj interface{}, value interface{}) error { + for _, fn := range es.afterUnmarshal { + if err := fn(ctx, obj, value); err != nil { + return err + } + } + return nil + } + + func (e *executableSchema) Schema() *ast.Schema { - return parsedSchema + return gqlparser.MustLoadSchema(e.sources...) } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { diff --git a/codegen/input.gotpl b/codegen/input.gotpl index 126ff661c3..dcd125399a 100644 --- a/codegen/input.gotpl +++ b/codegen/input.gotpl @@ -88,7 +88,8 @@ } } - return {{$it}}, nil + err := ec.afterUnmarshalInput(ctx, &{{$it}}, obj) + return {{$it}}, err } {{- end }} {{ end }} diff --git a/codegen/root_.gotpl b/codegen/root_.gotpl index dcfc84d0ed..e1cfa1cf0a 100644 --- a/codegen/root_.gotpl +++ b/codegen/root_.gotpl @@ -20,6 +20,7 @@ func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { resolvers: cfg.Resolvers, directives: cfg.Directives, complexity: cfg.Complexity, + sources: sources, } } @@ -69,10 +70,20 @@ type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot complexity ComplexityRoot + sources []*ast.Source + afterUnmarshal []func(ctx context.Context, obj interface{}, value interface{}) error } +func (es *executableSchema) afterUnmarshalInput(ctx context.Context, obj interface{}, value interface{}) error { + for _, fn := range es.afterUnmarshal { + if err := fn(ctx, obj, value); err != nil { + return err + } + } + return nil +} func (e *executableSchema) Schema() *ast.Schema { - return parsedSchema + return gqlparser.MustLoadSchema(e.sources...) } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { @@ -270,4 +281,4 @@ var sources = []*ast.Source{ {Name: {{$source.RelativePath|quote}}, Input: {{if (not $source.Embeddable)}}{{$source.Source|rawQuote}}{{else}}sourceData({{$source.RelativePath|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, {{- end }} } -var parsedSchema = gqlparser.MustLoadSchema(sources...) +// var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/plugin/federation/federation.gotpl b/plugin/federation/federation.gotpl index 7cf84287eb..1fc3539c9b 100644 --- a/plugin/federation/federation.gotpl +++ b/plugin/federation/federation.gotpl @@ -18,7 +18,7 @@ func (ec *executionContext) __resolve__service(ctx context.Context) (fedruntime. var sdl []string - for _, src := range sources { + for _, src := range ec.sources { if src.BuiltIn { continue }