Comments (2)
- 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.
- No types for the
info
parameter:
It should be typed? Where are you seeing that it isn't?
- 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".
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.
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)
- How to avoid TypeScript errors when using ESM? HOT 7
- unionType issue/question HOT 1
- Is this package still maintained? HOT 6
- using nexus with cloudflare workers HOT 1
- Error when generating GraphQL schema from schema.prisma when referencing alternative/unique key. HOT 1
- Exclude `ok: Boolean!` from generate HOT 1
- Support directives for Spectaql document generation
- Guide for generating nexus in ESM HOT 1
- ESM support HOT 2
- Trouble running examples using npm. What is test:types?
- wrong npm version badge on npm page
- Experimental CRUD type error
- totalCount function "args" are not typed based on "additionalArgs" in the same way as "nodes" function
- Examples not working
- #441 breaks the use with raw GraphQLScalarType from library such as graphql-upload-minimal
- isTypeOf malfunctioning for Interfaces
- Critical dependency: the request of a dependency is an expression HOT 1
- Graphql recent Support
- How can I save DateTime objects using nexus?
- `NeedsResolver` type utility broken in TS 5.5.2 HOT 1
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 nexus.