GithubHelp home page GithubHelp logo

Comments (16)

Kinbaum avatar Kinbaum commented on June 16, 2024 2

@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.

Kinbaum avatar Kinbaum commented on June 16, 2024 1

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.

Kinbaum avatar Kinbaum commented on June 16, 2024 1

This is next specific. Works on my own infra

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024 1

Yeah they usually do not leverage jsdoc, oh well. Good to confirm thanks for sharing this!

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

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.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

Does anyone know if this is next specific or Vercel specific or the combination or…?

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

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.

Kinbaum avatar Kinbaum commented on June 16, 2024

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
}

Screen Shot 2023-04-13 at 4 51 22 PM

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

We also rely on global Nodejs types, so this already works:

CleanShot 2023-04-16 at 00 46 28@2x

from graphql-request.

Kinbaum avatar Kinbaum commented on June 16, 2024

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.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

@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.

CleanShot 2023-04-16 at 23 14 00@2x

Can you clarify what is not working for you?

from graphql-request.

Kinbaum avatar Kinbaum commented on June 16, 2024

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.

Kinbaum avatar Kinbaum commented on June 16, 2024

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.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

I added a test that shows this works. Let me know if that test case is not covering this issue.

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on June 16, 2024

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.

Kinbaum avatar Kinbaum commented on June 16, 2024

Will do, thanks for the response I appreciate it

from graphql-request.

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.