作者:乐在TV | 来源:互联网 | 2023-09-05 13:32
addedexecutionofsystemdirectivesforARGUMENT_DEFINITIONandINPUT_FIELD_DEFINITION
added execution of system directives for ARGUMENT_DEFINITION and INPUT_FIELD_DEFINITION
generating code for arguments for example when adding a Directive instead of
1 2 3 4 5 6 7 8
| golang
if tmp, ok := rawArgs["Id"]; ok {
var err error
arg0, err = graphql.UnmarshalID(tmp)
if err != nil {
return nil, err
}
} |
will be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| golang
if tmp, ok := rawArgs["Id"]; ok {
argm0, err := chainFieldMiddleware([]graphql.FieldMiddleware{
func(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {
min := "0"
return e.directives.AssertRange(ctx, tmp, n, &min, nil, nil)
},
}...)(ctx, func(ctx2 context.Context) (args0 interface{}, err error) {
args0, err = graphql.UnmarshalID(tmp)
if err != nil {
return nil, err
}
return
})
if err != nil {
return nil, err
}
if data, ok := argm0.(string); ok {
arg0 = data
} else {
return nil, errors.New("expect string")
}
} |
if the argument is type input, the code will be added in addition to the previous code and the previous code will be added (for example)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| golang
if tmp, ok := rawArgs["input"]; ok {
var err error
arg0, err = UnmarshalDataInput(tmp)
if err != nil {
return nil, err
}
arg0, err := e.DataInputMiddleware(ctx, arg0)
if err != nil {
return nil, err
}
} |
and added input middleware(for example) or empty middleware
1 2 3 4 5 6 7 8 9 10 11 12 13
| golang
func (e *executableSchema) DataInputMiddleware(ctx context.Context, obj *models.DataInput) (*models.DataInput, error) {
if obj.InternalData != nil {
var err error
obj.InternalData, err = e.CoordinatesInputMiddleware(ctx, obj.InternalData)
if err != nil {
return nil, err
}
}
return obj, nil
} |
该提问来源于开源项目:99designs/gqlgen
cannot convert nil (untyped nil value) to string
invalid schema
1
| directive (min: Int!, max: Int, message: String!) |
message MUST NOT be null
1
| (min: 2, max: 5, message:"not valid") |
and if not set
schema invalid, but there is no error
and for example if use `` from gqlgen/example/todo/schema.graphql without role MUST be error when generate go files, but its working as if you were the owner
invalid operation: (&args0) (value of type *interface{}) has no field or method UnmarshalGQL
updated generate args