From b7d7b076d3505084e2a8d14b35c112aef1a88f1f Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Wed, 7 Dec 2022 16:05:01 -0800 Subject: [PATCH] fix(gatsby-source-wordpress): Add back nodeType field that was removed in last version (#37212) * canary commit * move typedef interfaces definition to __all type filter * add the nodeType field to any type that implements Node * Revert "canary commit" This reverts commit fd7f83dfeb491412494a4f78529b8b050b6162e9. * update snapshot --- .../__tests__/__snapshots__/index.js.snap | 37 +++++++++++++++++++ .../create-schema-customization/index.js | 5 --- .../type-filters.js | 17 ++++++--- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/integration-tests/gatsby-source-wordpress/__tests__/__snapshots__/index.js.snap b/integration-tests/gatsby-source-wordpress/__tests__/__snapshots__/index.js.snap index 535ee9d1d3c12..1b77b2c099020 100644 --- a/integration-tests/gatsby-source-wordpress/__tests__/__snapshots__/index.js.snap +++ b/integration-tests/gatsby-source-wordpress/__tests__/__snapshots__/index.js.snap @@ -951,6 +951,7 @@ Array [ "seo", "viewer", "writingSettings", + "nodeType", "id", "parent", "children", @@ -1114,6 +1115,7 @@ Array [ "termGroupId", "termTaxonomyId", "uri", + "nodeType", "parent", "children", "internal", @@ -1311,6 +1313,7 @@ Array [ "replies", "status", "type", + "nodeType", "parent", "children", "internal", @@ -1325,6 +1328,7 @@ Array [ "id", "name", "url", + "nodeType", "parent", "children", "internal", @@ -1533,6 +1537,7 @@ Array [ "id", "name", "url", + "nodeType", "parent", "children", "internal", @@ -1634,6 +1639,7 @@ Array [ "slug", "status", "uri", + "nodeType", "parent", "children", "internal", @@ -1801,6 +1807,7 @@ Array [ "showInRest", "showUi", "uri", + "nodeType", "parent", "children", "internal", @@ -5800,6 +5807,7 @@ Array [ "slug", "status", "uri", + "nodeType", "parent", "children", "internal", @@ -5916,6 +5924,7 @@ Array [ "id", "parentDatabaseId", "parentId", + "nodeType", "parent", "children", "internal", @@ -5989,6 +5998,7 @@ Array [ "termGroupId", "termTaxonomyId", "uri", + "nodeType", "parent", "children", "internal", @@ -6111,6 +6121,7 @@ Array [ "status", "title", "uri", + "nodeType", "localFile", "parent", "children", @@ -6275,6 +6286,7 @@ Array [ "menuItems", "name", "slug", + "nodeType", "parent", "children", "internal", @@ -6359,6 +6371,7 @@ Array [ "title", "uri", "url", + "nodeType", "parent", "children", "internal", @@ -6434,6 +6447,7 @@ Array [ "isContentNode", "isTermNode", "uri", + "nodeType", "parent", "children", "internal", @@ -6608,6 +6622,7 @@ Array [ "authorDatabaseId", "authorId", "id", + "nodeType", "parent", "children", "internal", @@ -6687,6 +6702,7 @@ Array [ "commentCount", "commentStatus", "id", + "nodeType", "parent", "children", "internal", @@ -6747,6 +6763,7 @@ Array [ "fields": Array [ "content", "id", + "nodeType", "parent", "children", "internal", @@ -6807,6 +6824,7 @@ Array [ "fields": Array [ "excerpt", "id", + "nodeType", "parent", "children", "internal", @@ -6869,6 +6887,7 @@ Array [ "featuredImageDatabaseId", "featuredImageId", "id", + "nodeType", "parent", "children", "internal", @@ -6947,6 +6966,7 @@ Array [ "fields": Array [ "id", "menuOrder", + "nodeType", "parent", "children", "internal", @@ -7007,6 +7027,7 @@ Array [ "fields": Array [ "id", "isRevision", + "nodeType", "parent", "children", "internal", @@ -7072,6 +7093,7 @@ Array [ Object { "fields": Array [ "id", + "nodeType", "parent", "children", "internal", @@ -7132,6 +7154,7 @@ Array [ "fields": Array [ "id", "title", + "nodeType", "parent", "children", "internal", @@ -7194,6 +7217,7 @@ Array [ "pingStatus", "pinged", "toPing", + "nodeType", "parent", "children", "internal", @@ -7303,6 +7327,7 @@ Array [ "template", "title", "uri", + "nodeType", "beforeChangeNodeTest", "parent", "children", @@ -7577,6 +7602,7 @@ Array [ "title", "toPing", "uri", + "nodeType", "beforeChangeNodeTest", "parent", "children", @@ -7649,6 +7675,7 @@ Array [ "termGroupId", "termTaxonomyId", "uri", + "nodeType", "parent", "children", "internal", @@ -8019,6 +8046,7 @@ Array [ "template", "title", "uri", + "nodeType", "parent", "children", "internal", @@ -8716,6 +8744,7 @@ Array [ "termGroupId", "termTaxonomyId", "uri", + "nodeType", "parent", "children", "internal", @@ -8864,6 +8893,7 @@ Array [ "showInQuickEdit", "showInRest", "showUi", + "nodeType", "parent", "children", "internal", @@ -9010,6 +9040,7 @@ Array [ "termGroupId", "termTaxonomyId", "uri", + "nodeType", "parent", "children", "internal", @@ -9122,6 +9153,7 @@ Array [ "template", "title", "uri", + "nodeType", "parent", "children", "internal", @@ -9228,6 +9260,7 @@ Array [ "template", "title", "uri", + "nodeType", "parent", "children", "internal", @@ -9334,6 +9367,7 @@ Array [ "template", "title", "uri", + "nodeType", "parent", "children", "internal", @@ -9412,6 +9446,7 @@ Array [ "isContentNode", "isTermNode", "uri", + "nodeType", "parent", "children", "internal", @@ -9495,6 +9530,7 @@ Array [ "uri", "url", "username", + "nodeType", "parent", "children", "internal", @@ -9565,6 +9601,7 @@ Array [ "displayName", "id", "name", + "nodeType", "parent", "children", "internal", diff --git a/packages/gatsby-source-wordpress/src/steps/create-schema-customization/index.js b/packages/gatsby-source-wordpress/src/steps/create-schema-customization/index.js index 88ced3038a379..57afc366b99d9 100644 --- a/packages/gatsby-source-wordpress/src/steps/create-schema-customization/index.js +++ b/packages/gatsby-source-wordpress/src/steps/create-schema-customization/index.js @@ -67,11 +67,6 @@ const customizeSchema = async ({ actions, schema, store: gatsbyStore }) => { break } - if (type.interfaces && builtType?.config) { - builtType.config.interfaces ||= [] - builtType.config.interfaces.push(...buildInterfacesListForType(type)) - } - if (builtType) { typeDefs.push(builtType) } diff --git a/packages/gatsby-source-wordpress/src/steps/create-schema-customization/type-filters.js b/packages/gatsby-source-wordpress/src/steps/create-schema-customization/type-filters.js index 17f23ea92c7f8..85e6ab0dbb647 100644 --- a/packages/gatsby-source-wordpress/src/steps/create-schema-customization/type-filters.js +++ b/packages/gatsby-source-wordpress/src/steps/create-schema-customization/type-filters.js @@ -1,11 +1,18 @@ +import { buildInterfacesListForType } from "./helpers" + export const typeDefinitionFilters = [ { typeName: `__all`, - typeDef: typeDef => { - /** - * @todo once WPGraphQL has a DateTime Scalar, use that to find date fields - * instead of the below fieldnames - */ + typeDef: (typeDef, { type }) => { + if (type.interfaces && typeDef) { + typeDef.interfaces ||= [] + typeDef.interfaces.push(...buildInterfacesListForType(type)) + } + + if (typeDef?.interfaces?.includes(`Node`)) { + // used to filter by different node types within a node interface + typeDef.fields.nodeType = `String` + } if (typeDef?.fields?.date) { const dateField = {