Comments (2)
Thinking about if hooks can return result types. This would facilitate the flexibility for extensions to retry hooks arbitrarily. It would also permit other use-cases than retry, not specific to it.
// ...
let result = await exchange({....})
let i=0
while (result instanceof Error) {
if (i > 3) return result // error
i++
result = await exchange({....})
}
const { unpack } = result
// ...
To opt out of error error handling users could use .throw()
on the executed hook:
// ...
const { unpack } = await exchange({....}).orThrow()
// ...
When an extension would re-run a hook it would mean that all the extensions lower in the stack would execute again as well.
from graphql-request.
After banging my head on this a few days I think I've realized what I want to do is impossible.
await run(
async function foo({ a }) {
const resultA1 = await a()
const resultB1 = await resultA1.b() // imagine this is an error
const resultB2 = await resultA1.b()
return resultB2
},
async function bar({ a }) {
const resultA1 = await a()
const resultB1 = await resultA1.b()
if (resultB1 instanceof Error) throw resultB1
return resultB1
},
)
If extension foo
does a retry on hook b
there is no way for extension bar
to then resume from await resultA1.b()
which is what so far the ideas in this issue would assume would happen. Well... no it is not possible to "rewind" the function body like that.
The inability to retry a hook is a DX miss here... had the hooks been separate functions it would have been possible to add retry to any of them. The single function body approach seems to give up that potential.
If the extension is the last in the stack, it actually can retry because there is no rewinding of downstream functions required. What could a configuration API make that feature obvious and safe though?
Graffle
.create()
.extend(...)
.extend(...)
.extend({
anyware: async (...) => { ... },
anywareCatch: async ({ exchange }) => {
let result = await exchange()
if (result instance Error) result = ...
}
})
The typing for a catch extension will need to differ. Its hooks will return an either type that exposes the error for programatic control.
How would this look in Anyware? Just a new catch
parameter I think...
anyware.run({
initialInput,
extensions,
catch,
})
from graphql-request.
Related Issues (20)
- Create separated npm package for CLI functionality HOT 8
- Please give feedback to the GraphQL JS WG HOT 2
- 7 doesnt work on nextjs HOT 4
- 7 broken on Expo/RN project HOT 1
- TypeScript doesn't recognize the types and fail v7 HOT 1
- Document the requirement of tooling support for package.exports HOT 8
- [7.0.1] broken types HOT 16
- Graffle helper functions
- Extension system
- TypedDocumentNode support
- Support GET requests
- Add support for NextJS revalidate/tags directly from request HOT 2
- investigate quality tools HOT 1
- Types broken in v7 HOT 2
- Cannot find module 'graphql-request' or its corresponding type declarations. HOT 11
- Error: Could not convert argument of type symbol to string. HOT 1
- Spreading request headers object in middleware function doesn't work as per examples HOT 2
- Extend graphql return mode to include the response when transport is http
- Typescript cannot find type `RequestOptions` 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 graphql-request.