Comments (3)
Resolve in subscription resolvers is mostly useless, everything is handled through subscribe.
As I understand it, this isn't always true, subscribe
sets up the subscription, but the resolve
is used to format the data from the published event into the actual shape needed to fulfill the subscription query. If these do map 1:1, for now you can just add an identity function: resolve: t => t
as a property the config.
I don't have any strong opinions here, if this is a common enough case I can consider making this optional - didn't really spend as much time thinking about the guarantees around type-safety in subscriptions as in the rest of the schema.
from nexus.
@tgriesser Yesterday, I also stuck with this problem. My subscription returns data from the async iterator as it's needed for the target type. Maybe resolver should be t => t
by default?
from nexus.
Ideally resolve
is required when the event payloads returned by subscribe are not 1:1, and otherwise optional (possibly even hidden).
Achieving this will require some advanced techniques though, and would probably be out of scope for @nexus/schema
.
Need to think it through but roughly I think: 1) we can use the TSC API to extract return type from subscribe
2) compare with return type of what resolve wants 3) require resolve if they differ meaningfully.
That is non-trivial to make robust and performant, but not so bad.
We'd want @nexus/schema
to make this possible but the work involved here is, again, out of scope. Only Nexus framework goes to the level of using the TSC API right now.
I think @tgriesser's suggestion is a great one for @nexus/schema
users.
I'll leave this issue here for a bit, but probably migrate it to the Nexus repo soon.
from nexus.
Related Issues (20)
- Not possible to define sourceType with another objectType HOT 1
- t.nullable.bytes is not a function
- Using NexusTypes with ZOD validation tool (Or yup, joy ...) HOT 3
- 'isTypeOf' does not exist in type 'NexusObjectTypeConfig HOT 1
- 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
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.