{"id":186,"date":"2021-05-18T17:31:01","date_gmt":"2021-05-18T23:31:01","guid":{"rendered":"https:\/\/developers.wpengine.com\/blog\/?p=186"},"modified":"2026-02-05T21:02:39","modified_gmt":"2026-02-06T03:02:39","slug":"graphql-code-generator-for-wpgraphql","status":"publish","type":"post","link":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/","title":{"rendered":"GraphQL Code Generator for WPGraphQL"},"content":{"rendered":"\n<p>When getting started with TypeScript, developers quickly become accustomed to defining their typings. For a React component that&#8217;s responsible for rendering a single blog post&#8217;s content, you may write something like this:<\/p>\n\n\n<pre class=\"wp-block-code language-ts\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span>type Avatar = {\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-attr\">url<\/span>: string;\n<\/span><\/span><span class='shcb-loc'><span>};\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>type User = {\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-attr\">name<\/span>: string;\n<\/span><\/span><span class='shcb-loc'><span>  avatar: Avatar;\n<\/span><\/span><span class='shcb-loc'><span>};\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>type Post = {\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-attr\">databaseId<\/span>: number;\n<\/span><\/span><span class='shcb-loc'><span>  title: string;\n<\/span><\/span><span class='shcb-loc'><span>  slug: string;\n<\/span><\/span><span class='shcb-loc'><span>  excerpt: string;\n<\/span><\/span><span class='shcb-loc'><span>  content: string;\n<\/span><\/span><span class='shcb-loc'><span>  author: {\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-attr\">node<\/span>: User;\n<\/span><\/span><span class='shcb-loc'><span>  }\n<\/span><\/span><span class='shcb-loc'><span>};\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>type Props = {\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-attr\">post<\/span>: Post;\n<\/span><\/span><span class='shcb-loc'><span>};\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">BlogPost<\/span>(<span class=\"hljs-params\">props: Props<\/span>) <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">const<\/span> { post } = props;\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">return<\/span> (\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">article<\/span>&gt;<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\">      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>{post.title}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">      {\/* etc. *\/}<\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">article<\/span>&gt;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">  );<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">}<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can see that the <code>BlogPost<\/code> component accepts an argument with a type of <code>Props<\/code>, which itself uses a type of <code>Post<\/code>. <code>Post<\/code> uses the <code>User<\/code> type, which in turn uses the <code>Avatar<\/code> type. Sure, you may be able to nest&nbsp;<em>some<\/em>&nbsp;of those types inside others to make things a bit more concise, but you still end up with quite a few type definitions. While this code works fine, you may find that it is time-consuming to create all the types for your project manually.<\/p>\n\n\n\n<p>If your project sources its data from a GraphQL API, you may look at the GraphQL schema and think:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8220;Wait&#8230;since my GraphQL schema is strongly typed, can&#8217;t I just leverage those same types in my TypeScript code instead of reinventing the wheel?&#8221;<\/p><\/blockquote>\n\n\n\n<p>You, my astute friend, are in luck! That is indeed possible using&nbsp;<a target=\"_blank\" href=\"https:\/\/www.graphql-code-generator.com\/\" rel=\"noreferrer noopener\">GraphQL Code Generator<\/a>, a.k.a. &#8220;GraphQL Codegen.&#8221; This free, open-source tool can use your GraphQL schema to generate TypeScript typings. This image sums it up nicely:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/graphql-codegen-1024x675.png\" alt=\"\" class=\"wp-image-187\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Set Up<\/h2>\n\n\n\n<p>Let&#8217;s learn how you set up GraphQL Codegen in your headless WordPress projects that use WPGraphQL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable GraphQL Introspection<\/h3>\n\n\n\n<p>In the WordPress admin sidebar of your local environment, head to <code>GraphQL<\/code> &gt; <code>Settings<\/code>. Make sure the <strong>Enable Public Introspection<\/strong> option is checked. This will allow GraphQL Code Generator to run an introspection query against your GraphQL endpoint to get the entire schema.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-13-at-4.28.30-PM-1024x152.png\" alt=\"\" class=\"wp-image-188\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Initialize GraphQL Code Generator<\/h3>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\"><li>Head over to the GraphQL Code Generator <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/getting-started\/installation\">Getting Started documentation page<\/a>. Follow the steps for installing the <code>graphql<\/code> and <code>@graphql-codegen\/cli<\/code> NPM packages.<\/li><li>Run <code>npx graphql-codegen init<\/code> (or <code>yarn graphql-codegen init<\/code>) to launch the initialization wizard. Below, we&#8217;ll cover what to enter for each prompt.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">What type of application are you building?<\/h4>\n\n\n\n<p>Select Angular\/React\/any thing your heart desires.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Where is your schema?<\/h4>\n\n\n\n<p>Paste in your local WordPress site&#8217;s GraphQL endpoint. You can see it on the WPGraphQL settings page here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-13-at-4.35.50-PM-1024x227.png\" alt=\"\" class=\"wp-image-189\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Where are your operations and fragments?<\/h4>\n\n\n\n<p>Enter the path to where the <code>.graphql<\/code> files containing operations and fragments. Example: <code>src\/*<em>*\/<\/em>*.graphql<\/code>. If you don&#8217;t have <code>.graphql<\/code> files in your project, just hit enter to go to the next step.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Pick plugins<\/h4>\n\n\n\n<p>Make sure to check <code>TypeScript (required by other typescript plugins<\/code>. Look if <code>TypeScript Operations (operations and fragments)<\/code> only if you have <code>.graphql<\/code> files containing GraphQL operations and fragments in your project; un-check it, if not. Leave all other options unchecked and hit enter to continue.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Where to write the output<\/h4>\n\n\n\n<p>Enter <code>generated\/graphql.ts<\/code>. This tells GraphQL Code Generator what file it should write the generated typings.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Do you want to generate an introspection file?<\/h4>\n\n\n\n<p>Choose &#8220;No&#8221;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to name the config file?<\/h4>\n\n\n\n<p>Hit enter to accept the default <code>codegen.yml<\/code> filename.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What script in package.json should run the codegen?<\/h4>\n\n\n\n<p>Enter <code>generate<\/code>.<\/p>\n\n\n\n<p>The GraphQL Codegen CLI will: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Generate a <code>codegen.yml<\/code> configuration file based on your answers<\/li><li>Add a few NPM packages to your <code>devDependencies<\/code> to your project<\/li><li>Add a new <code>generate<\/code> script in <code>package.json<\/code>. You&#8217;ll be able to run whenever you want to generate your typings<\/li><\/ul>\n\n\n\n<p>The command line output should look something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/graphql-codegen-cli-1024x734.png\" alt=\"\" class=\"wp-image-190\"\/><\/figure>\n\n\n\n<p>Next, run <code>npm install<\/code> (or <code>yarn<\/code>) to install the new <code>devDependencies<\/code>.<\/p>\n\n\n\n<p>If you do not have <code>.graphql<\/code> files containing GraphQL operations and fragments in your project, remove the entire <code>documents:<\/code> line from <code>codegen.yml<\/code> and save the file. If you don&#8217;t do this, GraphQL Codegen will throw an error when you try to generate your typings since it will be unable to find those files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Generate Your Typings<\/h2>\n\n\n\n<p>With typing set up complete , run <code>npm run generate<\/code> to generate your typings. GraphQL Code Generator will access the GraphQL schema via your local site&#8217;s GraphQL endpoint and generate TypeScript typings.<\/p>\n\n\n\n<p>Congrats! You have now used your GraphQL schema to generate TypeScript typings you can use in your frontend app! You can check out the <code>generated\/graphql.ts<\/code> file to see all the generated typings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use the Generated Types<\/h2>\n\n\n\n<p>Let&#8217;s revisit our <code>BlogPost<\/code> component example from the beginning of this blog post. Rather than all of those type definitions we had created manually, we can instead do this:<\/p>\n\n\n<pre class=\"wp-block-code language-ts\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Post } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"..\/..\/generated\/graphql\"<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>type Props = {\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-attr\">post<\/span>: Post;\n<\/span><\/span><span class='shcb-loc'><span>};\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">BlogPost<\/span>(<span class=\"hljs-params\">props: Props<\/span>) <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">const<\/span> { post } = props;\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">return<\/span> (\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">article<\/span>&gt;<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\">      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>{post.title}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">      {\/* etc. *\/}<\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">article<\/span>&gt;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">  );<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"xml\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\"><span class=\"hljs-tag\">}<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can see that this is quite a bit simpler. Rather than creating our typings manually, we can leverage the ones that GraphQL Codegen generated for us.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Generate Typings<\/h2>\n\n\n\n<p>You can commit the <code>generated\/graphql.ts<\/code> to your version control system so the generated types are stored alongside the rest of your project. Anytime you want to regenerate the types (such as if you make changes to the GraphQL schema or install a WPGraphQL extension), you can run <code>npm run generate<\/code> again. This will overwrite your current <code>generated\/graphql.ts<\/code> file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Plugins &amp; Integrations<\/h2>\n\n\n\n<p>We&#8217;ve learned the basics of how to set up and run GraphQL Code Generator to generate typings using our GraphQL schema. If you want to go further and automatically generate even more code for your project, I encourage you to check out the <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/plugins\/index\">GraphQL Code Generator plugins<\/a> available.<\/p>\n\n\n\n<p>There are plugins available for <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/plugins\/typescript-react-apollo\">Apollo Client<\/a>, <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/plugins\/typescript-react-query\">React Query<\/a>, <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/plugins\/typescript-graphql-request\">GraphQL Request<\/a>. and other popular libraries that generate other things for you, such as custom React hooks, higher-order components, etc.<\/p>\n\n\n\n<p><strong>Note for Gatsby users<\/strong>: an integration also exists to generate typings from Gatsby&#8217;s unified GraphQL data layer. See the <a href=\"https:\/\/www.graphql-code-generator.com\/docs\/integrations\/gatsby\">documentation<\/a> for details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>I hope this post is helps you understand the benefits you can gain by using GraphQL Code Generator to generate typings for your frontend JavaScript app based on your GraphQL schema. You should also have a good idea of how to set up GraphQL Codegen for your projects and run it to generate your types. Thanks for reading! ????<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When getting started with TypeScript, developers quickly become accustomed to defining their typings. For a React component that&#8217;s responsible for rendering a single blog post&#8217;s content, you may write something [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"footnotes":""},"categories":[23],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-headless"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>GraphQL Code Generator for WPGraphQL - Builders<\/title>\n<meta name=\"description\" content=\"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GraphQL Code Generator for WPGraphQL - Builders\" \/>\n<meta property=\"og:description\" content=\"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/\" \/>\n<meta property=\"og:site_name\" content=\"Builders\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-18T23:31:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-06T03:02:39+00:00\" \/>\n<meta name=\"author\" content=\"Kellen Mace\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wpebuilders\" \/>\n<meta name=\"twitter:site\" content=\"@wpebuilders\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kellen Mace\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/\"},\"author\":{\"name\":\"Kellen Mace\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/person\\\/e6e62698d757a8421cc9723ffa8b1be3\"},\"headline\":\"GraphQL Code Generator for WPGraphQL\",\"datePublished\":\"2021-05-18T23:31:01+00:00\",\"dateModified\":\"2026-02-06T03:02:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/\"},\"wordCount\":924,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/graphql-codegen-1024x675.png\",\"articleSection\":[\"Headless\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/\",\"name\":\"GraphQL Code Generator for WPGraphQL - Builders\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/graphql-codegen-1024x675.png\",\"datePublished\":\"2021-05-18T23:31:01+00:00\",\"dateModified\":\"2026-02-06T03:02:39+00:00\",\"description\":\"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/graphql-code-generator-for-wpgraphql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GraphQL Code Generator for WPGraphQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#website\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\",\"name\":\"Builders\",\"description\":\"Reimagining the way we build with WordPress.\",\"publisher\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\",\"name\":\"WP Engine\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/WP-Engine-Horizontal@2x.png\",\"contentUrl\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/WP-Engine-Horizontal@2x.png\",\"width\":348,\"height\":68,\"caption\":\"WP Engine\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/wpebuilders\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCh1WuL54XFb9ZI6m6goFv1g\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/person\\\/e6e62698d757a8421cc9723ffa8b1be3\",\"name\":\"Kellen Mace\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g\",\"caption\":\"Kellen Mace\"},\"description\":\"Kellen Mace is the Manager of the Developer Relations team at WP Engine. He likes building modern web apps with SvelteKit, TypeScript, Tailwind, and AI tools.\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/author\\\/kellen-macewpengine-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GraphQL Code Generator for WPGraphQL - Builders","description":"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings","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:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/","og_locale":"en_US","og_type":"article","og_title":"GraphQL Code Generator for WPGraphQL - Builders","og_description":"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings","og_url":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/","og_site_name":"Builders","article_published_time":"2021-05-18T23:31:01+00:00","article_modified_time":"2026-02-06T03:02:39+00:00","author":"Kellen Mace","twitter_card":"summary_large_image","twitter_creator":"@wpebuilders","twitter_site":"@wpebuilders","twitter_misc":{"Written by":"Kellen Mace","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#article","isPartOf":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/"},"author":{"name":"Kellen Mace","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/person\/e6e62698d757a8421cc9723ffa8b1be3"},"headline":"GraphQL Code Generator for WPGraphQL","datePublished":"2021-05-18T23:31:01+00:00","dateModified":"2026-02-06T03:02:39+00:00","mainEntityOfPage":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/"},"wordCount":924,"commentCount":0,"publisher":{"@id":"https:\/\/wpengine.com\/builders\/#organization"},"image":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#primaryimage"},"thumbnailUrl":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/graphql-codegen-1024x675.png","articleSection":["Headless"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/","url":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/","name":"GraphQL Code Generator for WPGraphQL - Builders","isPartOf":{"@id":"https:\/\/wpengine.com\/builders\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#primaryimage"},"image":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#primaryimage"},"thumbnailUrl":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2021\/05\/graphql-codegen-1024x675.png","datePublished":"2021-05-18T23:31:01+00:00","dateModified":"2026-02-06T03:02:39+00:00","description":"Learn how you can set up GraphQL Code Generator in your headless WordPress projects that use WPGraphQL through generating typings","breadcrumb":{"@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/builders\/graphql-code-generator-for-wpgraphql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/builders\/"},{"@type":"ListItem","position":2,"name":"GraphQL Code Generator for WPGraphQL"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/builders\/#website","url":"https:\/\/wpengine.com\/builders\/","name":"Builders","description":"Reimagining the way we build with WordPress.","publisher":{"@id":"https:\/\/wpengine.com\/builders\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/builders\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/wpengine.com\/builders\/#organization","name":"WP Engine","url":"https:\/\/wpengine.com\/builders\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/logo\/image\/","url":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2024\/05\/WP-Engine-Horizontal@2x.png","contentUrl":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2024\/05\/WP-Engine-Horizontal@2x.png","width":348,"height":68,"caption":"WP Engine"},"image":{"@id":"https:\/\/wpengine.com\/builders\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/wpebuilders","https:\/\/www.youtube.com\/channel\/UCh1WuL54XFb9ZI6m6goFv1g"]},{"@type":"Person","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/person\/e6e62698d757a8421cc9723ffa8b1be3","name":"Kellen Mace","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/479f2598f161363ba2e78e1b085782477580ea3d5c4609cc9bce3be4945090d5?s=96&d=mm&r=g","caption":"Kellen Mace"},"description":"Kellen Mace is the Manager of the Developer Relations team at WP Engine. He likes building modern web apps with SvelteKit, TypeScript, Tailwind, and AI tools.","url":"https:\/\/wpengine.com\/builders\/author\/kellen-macewpengine-com\/"}]}},"_links":{"self":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":0,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}