Comments (16)
@jasonkuhrt Is the expectation then that I need to instantiate a new GraphQLClient each time I want to make a request? Is there no way to reuse the existing client; then just add this option for individual requests I want revalidated?
Yes, adding the option during instantiation works as expected, I just don't want that to apply to everything or have to instantiate multiple clients, which is why I was hoping for a way to add this option per request; much like how we can say client.setHeaders
or client.setEndpoint
from graphql-request.
I like it. If there’s a specific entry point for next, maybe also include the global fetch next extends as the default
from graphql-request.
This is next specific. Works on my own infra
from graphql-request.
Yeah they usually do not leverage jsdoc, oh well. Good to confirm thanks for sharing this!
from graphql-request.
Ideas:
- A new entry point: import … from “graphql-request/next”
- A global interface that can be augmented. Still requires user to do something.
- Combine the above two solutions.
- …
from graphql-request.
Does anyone know if this is next specific or Vercel specific or the combination or…?
from graphql-request.
Does anyone know if the next types are consumable easily from a lightweight package? The next fetch extension types might have Jsdoc for one thing which would be nice to inherit.
from graphql-request.
This is currently how next defines the NextFetchRequestConfig
// Extend the NodeJS namespace with Next.js-defined properties
declare namespace NodeJS {
interface RequestInit extends globalThis.RequestInit {
next?: NextFetchRequestConfig | undefined
}
}
interface NextFetchRequestConfig {
revalidate?: number | false
}
interface RequestInit {
next?: NextFetchRequestConfig | undefined
}
from graphql-request.
We also rely on global Nodejs types, so this already works:
from graphql-request.
Hey @jasonkuhrt not sure why this was closed. There’s no way currently to pass { next: { revalidate: 60 }}
to the underlying fetch.
Can you provide an example if I’m misunderstanding something?
This needs to be available on each transaction (client.request
) as certain calls are dynamic, while others are static, and some are static with the ability to have their contents “revalidated” after a certain amount of time.
from graphql-request.
@Kinbaum I was trying to show in my last screenshot that the static types are fine with the next
parameter added in the context of a Next.js 13 codebase.
Can you clarify what is not working for you?
from graphql-request.
This option needs to be able to be attached to the underlying fetch, as a sibling of headers, method, body, etc. Currently it’s completely ignored, which prevents static content from being revalidated.
Can probably pass the polyfilled global fetch next provides which looks for this option in the client setup; if it can’t automatically be leveraged
from graphql-request.
Here’s an implementation example:
request(StaticCMSPageContent, {
path,
language
})
This will fetch static page content during the build process.
Now if a content author changes the content and republishes, we need to let next know that this data can change and should be revalidated, without needing to rebuild/redeploy our application.
As it sits right now, this query will never revalidate its static contents.
I am looking for something like this to do that:
request(StaticCMSPageContent, {
path,
language
}, {
next: {
revalidate: 60
}
})
As I mentioned though, this is not a header, it’s special key Next added to the global fetch.
As you mentioned, not a types issue, a runtime problem.
from graphql-request.
I added a test that shows this works. Let me know if that test case is not covering this issue.
from graphql-request.
I understand, you're looking for a feature that would see configuration parity across the function and the class. I agree, but that's a different issue. I'll get around to that eventually, as I overhaul this library. For now you do have a workaround though at least.
Feel free to make a new feature request about the configuration aspects that are lacking for your use-case(s)!
from graphql-request.
Will do, thanks for the response I appreciate it
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
- investigate quality tools HOT 1
- Types broken in v7 HOT 2
- Extension that can retry a hook 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`
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.