Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directives on fields with custom scalars #544

Merged
merged 2 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if err != nil {
return it, err
}
if data, ok := tmp.({{ $field.TypeReference.GO }}) ; ok {
if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
it.{{$field.GoFieldName}} = data
} else {
return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
Expand Down
46 changes: 46 additions & 0 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions codegen/testserver/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ models:
model: "github.com/99designs/gqlgen/codegen/testserver.Error"
EmbeddedPointer:
model: "github.com/99designs/gqlgen/codegen/testserver.EmbeddedPointerModel"
ThirdParty:
model: "github.com/99designs/gqlgen/codegen/testserver.ThirdParty"
1 change: 1 addition & 0 deletions codegen/testserver/models-gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions codegen/testserver/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ input OuterInput {
inner: InnerInput!
}

scalar ThirdParty

input InputDirectives {
text: String! @length(min: 0, max: 7, message: "not valid")
inner: InnerDirectives!
innerNullable: InnerDirectives
thirdParty: ThirdParty @length(min: 0, max: 7, message: "not valid")
}

input InnerDirectives {
Expand Down
30 changes: 30 additions & 0 deletions codegen/testserver/thirdparty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package testserver

import (
"fmt"
"github.com/99designs/gqlgen/graphql"
"io"
"strconv"
)

type ThirdParty struct {
str string
}

func MarshalThirdParty(tp ThirdParty) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, err := io.WriteString(w, strconv.Quote(tp.str))
if err != nil {
panic(err)
}
})
}

func UnmarshalThirdParty(input interface{}) (ThirdParty, error) {
switch input := input.(type) {
case string:
return ThirdParty{str: input}, nil
default:
return ThirdParty{}, fmt.Errorf("unknown type for input: %s", input)
}
}