{"id":437961,"date":"2024-06-05T13:35:14","date_gmt":"2024-06-05T13:35:14","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=437961"},"modified":"2026-02-25T12:00:29","modified_gmt":"2026-02-25T12:00:29","slug":"nextjs-graphql-codegen","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/","title":{"rendered":"GraphQL CodeGen with Next.js"},"content":{"rendered":"\n<p>In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages.<\/p>\n\n\n\n<p>After that, we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our <a href=\"https:\/\/webkul.com\/blog\/project-setup-next-js\/\" target=\"_blank\" rel=\"noreferrer noopener\">next js project.<\/a><\/p>\n\n\n\n<p>Also, look no further and grab the opportunity to start your <a href=\"https:\/\/webkul.com\/magento-2-react-development-services\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 React development<\/a> with the certified&nbsp;<a href=\"https:\/\/webkul.com\/magento-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 development company<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction of CodeGen<\/h2>\n\n\n\n<p>GraphQL Codegen is a tool that simplifies working with GraphQL APIs in TypeScript by automatically generating types and queries based on our schema.<\/p>\n\n\n\n<p>It reduces the amount of boilerplate code you have to write and makes it easier to work with GraphQL APIs.<\/p>\n\n\n\n<p>To use it, we would define our schema in a .graphql or .graphqls file and then use a codegen plugin to generate the TypeScript types and queries which we are about to cover deeper.<\/p>\n\n\n\n<p>The generated code includes interfaces for your GraphQL types and functions for making queries and mutations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of CodeGen \u2013<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Automated Code Generation:   <\/strong><\/h3>\n\n\n\n<p>GraphQL Code Generator simplifies your development process by automatically creating typed queries, mutations, and subscriptions.<\/p>\n\n\n\n<p>These are created for front-end libraries like React, Next.js, and other various frameworks &amp; libraries.<\/p>\n\n\n\n<p>Whether you use Apollo Client, URQL, or React Query, it ensures consistent and type-safe code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Type Safety and Consistency:<\/strong><\/h3>\n\n\n\n<p>Manually managing GraphQL operation types can lead to issues like outdated typings and typos. <\/p>\n\n\n\n<p>By automating this process, GraphQL Code Generator enhances the stability of your stack and improves the developer experience.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Efficient Workflow:<\/strong> <\/h3>\n\n\n\n<p>Without GraphQL Code Generator, developers often write repetitive code for queries and mutations. <\/p>\n\n\n\n<p>By analyzing your GraphQL schema, the tool generates fully typed code, eliminating the need for manual TypeScript type maintenance and enhancing your development workflow.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Broad Language Support:<\/strong> <\/h3>\n\n\n\n<p>While GraphQL Code Generator supports TypeScript by default, it can also generate code for other languages. <\/p>\n\n\n\n<p>It automates common data fetching practices and improves type safety in code that would typically be manually written.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration Apollo client with Graphql Code-Gen \u2013<\/h2>\n\n\n\n<p>Our main focus will be on configuring GraphQL Codegen with Apollo Client in a Next.js environment.<br><br>To set up, we can follow this&nbsp;setup next js project&nbsp;blog that covers all about the setup.<\/p>\n\n\n\n<p>We assume you are familiar with setting up Apollo Client in a Next.js project. If not, you can refer to the Apollo client configuration with the Next.js blog for more insights.<br><\/p>\n\n\n\n<p>Let&#8217;s go with the steps to configure Apollo Client with GraphQL Codegen in a Next.js application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1:  Start by creating a new Next.js application:<\/strong><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\">npx create-next-app@latest \ncd next_codegen<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Installing Dependencies<\/strong><\/h3>\n\n\n\n<p>Install the necessary dependencies for Apollo Client, GraphQL, and GraphQL Codegen.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">npm install @apollo\/client graphql @graphql-codegen\/cli @graphql-codegen\/typescript @graphql-codegen\/typescript-operations @graphql-codegen\/typescript-react-apollo<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Initialising Apollo&nbsp;Client<\/strong><\/h3>\n\n\n\n<p>Initialize Apollo Client in your Next.js application. Create a new file named client.ts in the lib directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/\/ lib\/client.ts\nimport { ApolloClient, InMemoryCache } from &#039;@apollo\/client&#039;;\n\/\/ change the schema&#039;s uri with our graphql server end point\nexport const client = new ApolloClient({\n    uri: &#039;https:\/\/magento-endpoint\/graphql&#039;,\n    cache: new InMemoryCache(),\n});<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Integrating with&nbsp;Next.js<\/strong><\/h3>\n\n\n\n<p>In your Next.js app, wrap your pages with the Apollo Provider.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/\/ pages\/_app.js\n\nimport &quot;@\/styles\/globals.css&quot;;\nimport type { AppProps } from &quot;next\/app&quot;;\nimport { client } from &#039;@\/lib\/client&#039;;\nimport { ApolloProvider } from &#039;@apollo\/client&#039;;\nexport default function App({ Component, pageProps }: AppProps) {\n  return (\n    &lt;ApolloProvider client={client}&gt;\n      &lt;Component {...pageProps} \/&gt;\n    &lt;\/ApolloProvider&gt;\n  );\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5: Configuring GraphQL&nbsp;Codegen<\/strong><\/h3>\n\n\n\n<p>Create a codegen.ts file in the root directory of your project and define the configuration with our graphql server endpoint for GraphQL Codegen:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/\/ codegen.ts \n\/\/ change the schema&#039;s uri with our graphql server end point\nmodule.exports = {\n    overwrite: true,\n    schema:&#039;https:\/\/magento-endpoint\/graphql&#039;,\n    documents: &#091;\n      &#039;graphql\/**\/*.graphql&#039;,\n    ],\n    generates: {\n      &#039;generated\/graphql.tsx&#039;: {\n        plugins: &#091;\n          &#039;typescript&#039;,\n          &#039;typescript-operations&#039;,\n          &#039;typescript-react-apollo&#039;\n        ]\n      }\n    }\n  };<\/pre>\n\n\n\n<p>Now we need to create queries and mutations in our graphql folder as configured in our codegen.ts.<br><\/p>\n\n\n\n<p>Here graphql directory holds all queries and mutations files, here our products.query.graphql will be<br><\/p>\n\n\n\n<p>there for fetching the products list, likewise, we can also create a mutation in the same directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\n\/\/ graphql\/products.query.graphql\nquery Products(\n  $filters: ProductAttributeFilterInput\n  $search: String\n  $pageSize: Int = 20\n  $currentPage: Int = 1\n) {\n  products(\n    filter: $filters\n    pageSize: $pageSize\n    currentPage: $currentPage\n    search: $search\n  ) {\n    aggregations {\n      attribute_code\n      label\n      options {\n        count\n        label\n        value\n      }\n    }\n    total_count\n    page_info {\n      current_page\n      page_size\n      total_pages\n    }\n    items {\n      uid\n      name\n      url_key\n      sku\n      new_from_date\n      only_x_left_in_stock\n      rating_summary\n      description {\n        html\n      }\n      thumbnail {\n        disabled\n        label\n        position\n        url\n      }\n      short_description {\n        html\n      }\n      price_range {\n        maximum_price {\n          discount {\n            amount_off\n            percent_off\n          }\n          final_price {\n            currency\n            value\n          }\n          regular_price {\n            currency\n            value\n          }\n        }\n      }\n    }\n  }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 6: Generating Queries and Mutations<\/strong><\/h3>\n\n\n\n<p>To generate TypeScript types and React Apollo hooks from your GraphQL queries and mutations. we use this below this command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\nnpx graphql-codegen --config codegen.ts<\/pre>\n\n\n\n<p>But instead of using this command, we can configure this command into package.json file, <\/p>\n\n\n\n<p>Here we have added<em>graphql-codegen &#8211;config codegen.ts<\/em> , this command will execute while we make the build using <strong>npm run build <\/strong>or whenever we run <strong>npm run generate<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">  &quot;scripts&quot;: {\n    &quot;dev&quot;: &quot;next dev&quot;,\n    &quot;build&quot;: &quot;next build &amp;&amp; graphql-codegen --config codegen.ts&quot;,\n    &quot;start&quot;: &quot;next start&quot;,\n    &quot;lint&quot;: &quot;next lint&quot;,\n    &quot;generate&quot;:&quot;graphql-codegen --config codegen.ts&quot;\n  },<\/pre>\n\n\n\n<p>After hitting the command, our hooks will be generated into a generated directory with graphql.tsx contains a bunch of hooks.\u00a0<\/p>\n\n\n\n<p>However, we can also change where we have to generate this directory, it is generated as our configurated codegen.ts file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/\/ codegen.ts \n\/\/ change the schema&#039;s uri with our graphql server end point\nmodule.exports = {\n    overwrite: true,\n    schema:&#039;https:\/\/magento-endpoint\/graphql&#039;,\n    documents: &#091;\n      ...\n    ],\n    generates: {\n      ...\n    }\n  };<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 7: Example&nbsp;Usage<\/strong><\/h3>\n\n\n\n<p>Now, let&#8217;s demonstrate how to use the generated hooks for query data in your project. <br>For instance, in your pages\/index.js.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\nimport { useProductsLazyQuery } from &#039;@\/generated\/graphql&#039;;\nimport { useEffect } from &#039;react&#039;;\n\nexport default function Home() {\n\n  const &#091;getPosProduct,{ data, loading, error } ]= useProductsLazyQuery();\n\n  useEffect(() =&gt; {\n    getPosProduct({\n      variables: {\n        search: &#039;&#039;,\n        pageSize: 20,\n        currentPage: 1\n      },\n    });\n  }, &#091;]);\n\n  if (loading) return &lt;p&gt;Loading...&lt;\/p&gt;\n  if (error?.message) return &lt;p&gt;{error.message}&lt;\/p&gt;\n\n  else {\n    return (\n      &lt;&gt;\n        &lt;main className={&#039;&#039;}&gt;\n          {\/* populate the product list *\/}\n        &lt;\/main&gt;\n      &lt;\/&gt;\n    );\n  }\n}<\/pre>\n\n\n\n<p>Now we can see our data in console.log<\/p>\n\n\n\n<p>Finally, our project structure will look like this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">NEXT_CODEGEN\/\n\u251c\u2500\u2500 generated\/\n\u2502    \u2514\u2500\u2500 graphql.tsx\n\u251c\u2500\u2500 graphql\/\n\u2502   \u2514\u2500\u2500 products.query.graphql\n\u251c\u2500\u2500 lib\/\n\u2502   \u2514\u2500\u2500 client.ts\n\u251c\u2500\u2500 node_modules\/\n\u251c\u2500\u2500 pages\/\n\u2502   \u251c\u2500\u2500 api\/\n\u2502   \u251c\u2500\u2500 _app.tsx\n\u2502   \u251c\u2500\u2500 _document.tsx\n\u2502   \u2514\u2500\u2500 index.tsx\n\u251c\u2500\u2500 public\/\n\u2502   \u251c\u2500\u2500 favicon.ico\n\u2502   \u251c\u2500\u2500 next.svg\n\u2502   \u2514\u2500\u2500 vercel.svg\n\u251c\u2500\u2500 styles\/\n\u2502   \u251c\u2500\u2500 globals.css\n\u2502   \u2514\u2500\u2500 Home.module.css\n\u251c\u2500\u2500 .eslintrc.json\n\u251c\u2500\u2500 .gitignore\n\u251c\u2500\u2500 codegen.ts\n\u251c\u2500\u2500 next-env.d.ts\n\u251c\u2500\u2500 next.config.mjs\n\u251c\u2500\u2500 package-lock.json\n\u251c\u2500\u2500 package.json\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 tsconfig.json<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In conclusion, combining <a href=\"https:\/\/webkul.com\/blog\/how-to-implement-magento-graphql-apis-with-nextjs-react\/\" target=\"_blank\" rel=\"noreferrer noopener\">GraphQL code generation<\/a> with Apollo Client and Next.js can significantly improve the development process.<\/p>\n\n\n\n<p>By utilizing code generation, we can ensure type safety and reduce manual errors in your GraphQL queries and mutations.<\/p>\n\n\n\n<p>Apollo Client provides a robust set of tools for working with GraphQL APIs, including caching and real-time updates, while Next.js offers server-side rendering and performance optimizations.<\/p>\n\n\n\n<p>Together, these technologies create a powerful stack for building efficient and scalable web applications with GraphQL.<\/p>\n\n\n\n<p>You can also have a look at our&nbsp;<a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 extensions<\/a>&nbsp;already crafted by certified Adobe Commerce Developers.<\/p>\n\n\n\n<p>For a personalized experience,&nbsp;<a href=\"https:\/\/webkul.com\/hire-magento-developers\/\" target=\"_blank\" rel=\"noreferrer noopener\">hire Magento developers&nbsp;<\/a>who can dedicatedly work on your customised e-commerce projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages. After that, we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project. Also, look no further and grab the opportunity to start your Magento 2 React development with the certified&nbsp;Magento 2 development <a href=\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":556,"featured_media":445844,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13575],"tags":[15455,15457,9219,2064,12682,6360,6359],"class_list":["post-437961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-next-js","tag-apollo-client","tag-codegen","tag-headless","tag-javascript","tag-nextjs","tag-react-ecommerce","tag-react-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GraphQL CodeGen with Next.js - Webkul Blog<\/title>\n<meta name=\"description\" content=\"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GraphQL CodeGen with Next.js - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-05T13:35:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-25T12:00:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Abhijeet Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhijeet Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\"},\"author\":{\"name\":\"Abhijeet Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/b5a304024503b6ebcc17ca4eb99c4761\"},\"headline\":\"GraphQL CodeGen with Next.js\",\"datePublished\":\"2024-06-05T13:35:14+00:00\",\"dateModified\":\"2026-02-25T12:00:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\"},\"wordCount\":829,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp\",\"keywords\":[\"Apollo-client\",\"codeGen\",\"Headless\",\"JavaScript\",\"nextjs\",\"react ecommerce\",\"react js\"],\"articleSection\":[\"next js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\",\"url\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\",\"name\":\"GraphQL CodeGen with Next.js - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp\",\"datePublished\":\"2024-06-05T13:35:14+00:00\",\"dateModified\":\"2026-02-25T12:00:29+00:00\",\"description\":\"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp\",\"width\":1200,\"height\":675,\"caption\":\"Graphql Codegen\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GraphQL CodeGen with Next.js\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/b5a304024503b6ebcc17ca4eb99c4761\",\"name\":\"Abhijeet Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7da15c87a9e02a6df1a4c86e9c28fdc2b835c30595c7476236c342bd212d70f8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7da15c87a9e02a6df1a4c86e9c28fdc2b835c30595c7476236c342bd212d70f8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Abhijeet Kumar\"},\"description\":\"Abhijeet is a skilled Software Engineer specializing in the Magento platform. With expertise in Magento 2 Headless Compatible Extensions and Headless PWA services, he crafts innovative solutions that enhance eCommerce functionality. A skilled developer, offering unique, headless solutions.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/abhijit-kumar018\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GraphQL CodeGen with Next.js - Webkul Blog","description":"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/","og_locale":"en_US","og_type":"article","og_title":"GraphQL CodeGen with Next.js - Webkul Blog","og_description":"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.","og_url":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2024-06-05T13:35:14+00:00","article_modified_time":"2026-02-25T12:00:29+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp","type":"image\/webp"}],"author":"Abhijeet Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Abhijeet Kumar","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/"},"author":{"name":"Abhijeet Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/b5a304024503b6ebcc17ca4eb99c4761"},"headline":"GraphQL CodeGen with Next.js","datePublished":"2024-06-05T13:35:14+00:00","dateModified":"2026-02-25T12:00:29+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/"},"wordCount":829,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp","keywords":["Apollo-client","codeGen","Headless","JavaScript","nextjs","react ecommerce","react js"],"articleSection":["next js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/","url":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/","name":"GraphQL CodeGen with Next.js - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp","datePublished":"2024-06-05T13:35:14+00:00","dateModified":"2026-02-25T12:00:29+00:00","description":"In this blog, we are about to explore the introduction of GraphQL CodeGen and its advantages then we will move toward the intricate configuration of GraphQL Codegen with apollo-client for our next js project.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/graphqlcodegen.webp","width":1200,"height":675,"caption":"Graphql Codegen"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/nextjs-graphql-codegen\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"GraphQL CodeGen with Next.js"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/b5a304024503b6ebcc17ca4eb99c4761","name":"Abhijeet Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7da15c87a9e02a6df1a4c86e9c28fdc2b835c30595c7476236c342bd212d70f8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7da15c87a9e02a6df1a4c86e9c28fdc2b835c30595c7476236c342bd212d70f8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Abhijeet Kumar"},"description":"Abhijeet is a skilled Software Engineer specializing in the Magento platform. With expertise in Magento 2 Headless Compatible Extensions and Headless PWA services, he crafts innovative solutions that enhance eCommerce functionality. A skilled developer, offering unique, headless solutions.","url":"https:\/\/webkul.com\/blog\/author\/abhijit-kumar018\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/437961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/556"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=437961"}],"version-history":[{"count":65,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/437961\/revisions"}],"predecessor-version":[{"id":528258,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/437961\/revisions\/528258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/445844"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=437961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=437961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=437961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}