Skip to content

Caching for graphql-request? #49438

@chaepling

Description

@chaepling

What is the improvement or update you wish to see?

Hi I'm using graphql-request with my next 13 app directory project. As far as I know, the default caching behavior caches my requests but since I am not using fecth() it doesn't work.

I searched for references for the same stack as mine but couldn't find one.

Since in app directory, layout.js and page.js can't share props, I fetch for the same data in both of them and cache doesn't work so it fetches the data from the server. And this is a huge waste for resources and I would like to know if there's anyway to use next 13's caching behavior on my graphql requests.

Is there any context that might help us understand?

stack:

"dependencies": {
    "@apollo/client": "^3.7.3",
    "next": "^13.4.1",
    "graphql": "^16.6.0",
    "graphql-request": "^5.1.0",
  }, 
  • request example
import request,{ gql } from "graphql-request";
import request from "graphql-request";

export const SHOW_DETAIL = gql`
  query ShowDetail($id: ID!) {
    show(id: $id) {
      seriesTotal
      synopType
      creatorId
    }
  }
`;

const data =
    await request(
      process.env.NEXT_PUBLIC_API_SERVER_URL! + "/graphql",
      SHOW_DETAIL,
    );

I use same request in Page and Layout and GenerateMetadata.

If I need to provide more information please let me know.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/building-your-application/data-fetching/caching#per-request-caching

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationRelated to Next.js' official documentation.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions