Skip to content

Commit

Permalink
allow source and schema manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
roderm committed Jul 17, 2023
1 parent b442fbf commit 08c23fe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
14 changes: 13 additions & 1 deletion codegen/generated!.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion codegen/input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
}
}

return {{$it}}, nil
err := ec.afterUnmarshalInput(ctx, &{{$it}}, obj)
return {{$it}}, err
}
{{- end }}
{{ end }}
15 changes: 13 additions & 2 deletions codegen/root_.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewExecutableSchema(cfg Config) graphql.ExecutableSchema {
resolvers: cfg.Resolvers,
directives: cfg.Directives,
complexity: cfg.Complexity,
sources: sources,
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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...)
2 changes: 1 addition & 1 deletion plugin/federation/federation.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 08c23fe

Please sign in to comment.