Git Product home page Git Product logo

Comments (2)

tgriesser avatar tgriesser commented on August 16, 2024 1
  1. how can i type the return value of my resolver, ...

With Nexus the idea is that you shouldn't ever need to annotate types in the resolver as you are doing above. By configuring the makeSchema's typegenAutoConfig you can configure what modules containing your types are imported (e.g. mongoose models, schemats output, just general classes or type files you've written). These types are then properly inferred on the fields based on the name of the type and the name of the field, using type inference/conditional types and global type merging.

The typegenAutoConfig uses a configurable regex matcher get the imports so they are auto-picked up based on the name of the types. You can pass debug: true as an option to the typegenAutoConfig to see a little more about how it's trying to find the associated type names. You can also specify them manually using a backingTypeMap option

typegenConfig is only if you wanted to build/supply your own type matcher that's more advanced than the one provided by the auto-config. The types generated are specific to nexus' use on the inference & merging and aren't really suitable for client re-use right now. I would like to add support for adding this as a config option, since I think having these are helpful and should be simple enough for us to allow, but for right now you might want to use something like graphql-code-generator.

If you want to get the resolver typing, for use elsewhere, for instance if you wanted to move your resolve fn into its own file, we export a FieldResolver helper.

  1. No types for the info parameter:

It should be typed? Where are you seeing that it isn't?

  1. is there a way to get type information on the root parameter?

Once you have the root types setup with the generator, the root types and return types shouldn't be "any" anymore, they should be correct based on what the field is resolving with. In order to see the types for the root, args, ctx, you can right click on the type and click "go to type definition".

screen shot 2019-02-11 at 11 56 53 am

I map this to cmd+' myself. Unfortunately jumping to the field expected return type doesn't work, and i'm not sure there's a good solution here right now, other than looking at the "field types" in the generated types file

from nexus.

Weakky avatar Weakky commented on August 16, 2024

other than looking at the "field types" in the generated types file

One quick suggestion here: I have put the main interface at the top of the file in the generated typings of nexus-prisma to ease navigation across the file. As TS doesn't require types to be defined before being used, it should be fine and make the file clearer

from nexus.

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.