Comments (3)
I haven't tested this, but you might be able to define the parent (Thing) yourself with the type you need, and point to it in your typemap.
The other way would be to define a custom scalar type for ListFooEnum, and your schema would become:
scalar CommaList
type Thing struct{
ListOfEnums: CommaList
}
from gqlgen.
I've ran into this as well. Certain cases make it really painful when the field names match, but have to be exposed through graphql by a different type.
A couple examples:
- struct with an ID field that is an
int
but needs to be astring
(for graphql) - a field is of type
time.Time
but it must be exposed to graphql as astring
in a certain format - a field is of a custom enum type that needs to be "mapped" (e.g.
iota
), but the parent struct would ideally be used directly
In cases where there is a type mismatch during code generation, it would be helpful if there was an option to behave as though there were no matching field at all (thus resolving the type mismatch with use of a resolver method).
The resolver code would then be "best-effort" where possible to auto-map fields. Anything that can't be done automatically would require a method for the Resolver interface, just like if there was no name match.
I don't feel strongly if that should be the default behavior or not though. I think a case could be made to change it, but to preserve current behavior, maybe via a flag like -ignore-type-mismatch
or -skip-type-mismatch
could be added. Then that flag could be set in the go:generate
line where necessary.
Anyway I'd be happy to take a shot at this if it sounds reasonable.
from gqlgen.
@jonlundy Now that #133 is merged, you should be able to put your mapping in a resolver for that single field (instead of getting type mismatch
).
from gqlgen.
Related Issues (20)
- unused parameter: ctx warnings in generated.go
- Subscription error: Error: Socket closed with event 1002 RSV1 set, bad opcode 7, bad MASK at Object.error
- @defer directive cancel load
- Codegen creates extra code on INPUT_OBJECT directive when using nested input fields? HOT 1
- Support for UUID type in ID scalars HOT 1
- Enable fix float point 2 decimal place
- Support for response.body.extensions on successful response?
- unnecessary entity resolvers generated when having multiple keys even after setting resolvable: false
- Unable to pass double braced '{{....}}' text or through to resolvers
- graph/foo/foo.graphqls doesn't have trailing newline
- Custom type for a specific field
- omit_resolver_fields option does not respect `models.<model>.fields.<field>.resolver` option HOT 1
- gqlgen converting the special chars to unicode breaking the frontend
- failed to build "_examples/websocket-initfunc/server/server.go"
- How long till 1.0? HOT 1
- Sharing input and output type schemas
- Is returning the stacktrace an option to enable?
- `mutation` with duplicate fields does not throw validation error
- gqlgen generate failed when the Resolver contains multiple-line comments
- could not import github.com/99designs/gqlgen (cannot find package "github.com/99designs/gqlgen" in GOROOT or GOPATH)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gqlgen.