{"id":48004,"date":"2022-12-06T22:00:43","date_gmt":"2022-07-10T02:49:37","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/"},"modified":"2024-01-15T12:29:22","modified_gmt":"2024-01-15T04:29:22","slug":"%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5"},"content":{"rendered":"<h1>\u73af\u5883<\/h1>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">NestJS 7.0.7<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">nestjs\/graphql 7.3.7<\/ul>\n<h1>\u9996\u5148\u7f16\u5199\u4ee3\u7801\u7684\u65b9\u6cd5<\/h1>\n<h2>\u5b89\u88dd<\/h2>\n<pre class=\"post-pre\"><code>yarn add graphql-type-json\r\nyarn add -D @types\/graphql-type-json\r\n<\/code><\/pre>\n<h2>\u8bbe\u7f6e<\/h2>\n<pre class=\"post-pre\"><code><span class=\"k\">import<\/span> <span class=\"nx\">graphqlTypeJson<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">graphql-type-json<\/span><span class=\"dl\">'<\/span>\r\n<span class=\"k\">import<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">Field<\/span><span class=\"p\">,<\/span> <span class=\"nx\">ObjectType<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">@nestjs\/graphql<\/span><span class=\"dl\">'<\/span>\r\n\r\n<span class=\"p\">@<\/span><span class=\"nd\">ObjectType<\/span><span class=\"p\">()<\/span>\r\n<span class=\"k\">export<\/span> <span class=\"kd\">class<\/span> <span class=\"nx\">SomeClass<\/span> <span class=\"p\">{<\/span>\r\n  <span class=\"p\">@<\/span><span class=\"nd\">Field<\/span><span class=\"p\">(()<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"nx\">graphqlTypeJson<\/span><span class=\"p\">,<\/span> <span class=\"p\">{<\/span> <span class=\"na\">nullable<\/span><span class=\"p\">:<\/span> <span class=\"kc\">true<\/span> <span class=\"p\">})<\/span>\r\n  <span class=\"nx\">json<\/span><span class=\"p\">?:<\/span> <span class=\"nx\">object<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<h2>\u786e\u8ba4<\/h2>\n<p>\u8bf7\u786e\u8ba4 schemal.gql \u6587\u4ef6\u4e2d\u5df2\u6dfb\u52a0\u4ee5\u4e0b\u6761\u76ee\u3002<\/p>\n<pre class=\"post-pre\"><code>type SomeClass {\r\n  json: JSON\r\n}\r\n\r\n\"\"\"\r\nThe `JSON` scalar type represents JSON values as specified by [ECMA-404](http:\/\/www.ecma-international.org\/publications\/files\/ECMA-ST\/ECMA-404.pdf).\r\n\"\"\"\r\nscalar JSON\r\n<\/code><\/pre>\n<h1>\u9996\u5148\u7684\u67b6\u6784\u8bbe\u8ba1\u65b9\u5f0f<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 NestJS 7.0.7 &nbsp; nestjs\/graphql 7.3.7 \u9996\u5148\u7f16\u5199\u4ee3\u7801\u7684\u65b9\u6cd5 \u5b89 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48004","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nestjs-graphql\u3011\u5904\u7406json\u7684\u65b9\u6cd5\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5\" \/>\n<meta property=\"og:description\" content=\"\u73af\u5883 NestJS 7.0.7 &nbsp; nestjs\/graphql 7.3.7 \u9996\u5148\u7f16\u5199\u4ee3\u7801\u7684\u65b9\u6cd5 \u5b89 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nestjs-graphql\u3011\u5904\u7406json\u7684\u65b9\u6cd5\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-10T02:49:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T04:29:22+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/\",\"name\":\"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2022-07-10T02:49:37+00:00\",\"dateModified\":\"2024-01-15T04:29:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","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:\/\/www.silicloud.com\/zh\/blog\/\u3010nestjs-graphql\u3011\u5904\u7406json\u7684\u65b9\u6cd5\/","og_locale":"zh_CN","og_type":"article","og_title":"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5","og_description":"\u73af\u5883 NestJS 7.0.7 &nbsp; nestjs\/graphql 7.3.7 \u9996\u5148\u7f16\u5199\u4ee3\u7801\u7684\u65b9\u6cd5 \u5b89 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nestjs-graphql\u3011\u5904\u7406json\u7684\u65b9\u6cd5\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2022-07-10T02:49:37+00:00","article_modified_time":"2024-01-15T04:29:22+00:00","author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/","name":"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2022-07-10T02:49:37+00:00","dateModified":"2024-01-15T04:29:22+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u3010NestJS\/GraphQL\u3011\u5904\u7406JSON\u7684\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nestjs-graphql%e3%80%91%e5%a4%84%e7%90%86json%e7%9a%84%e6%96%b9%e6%b3%95\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=48004"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48004\/revisions"}],"predecessor-version":[{"id":59473,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48004\/revisions\/59473"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=48004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=48004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=48004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}