GithubHelp home page GithubHelp logo

Override type mismatch about gqlgen HOT 3 CLOSED

jonlundy avatar jonlundy commented on May 22, 2024
Override type mismatch

from gqlgen.

Comments (3)

vektah avatar vektah commented on May 22, 2024

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.

mastercactapus avatar mastercactapus commented on May 22, 2024

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 a string (for graphql)
  • a field is of type time.Time but it must be exposed to graphql as a string 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.

mastercactapus avatar mastercactapus commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.