Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from gatsbyjs:master #698

Merged
merged 2 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,13 @@ Object {
},
},
},
"featuredImage": null,
"title": "Gutenberg: Common Blocks",
"featuredImage": Object {
"node": Object {
"altText": "",
"sourceUrl": "http://localhost:8001/wp-content/uploads/2020/03/1024x1024-300x300-1.png",
},
},
"title": "Gutenberg: Common Blocks DELTA SYNC",
},
Object {
"author": Object {
Expand Down Expand Up @@ -858,7 +863,7 @@ Object {
"title": "Gutenberg: Formatting Blocks",
},
Object {
"title": "Gutenberg: Common Blocks",
"title": "Gutenberg: Common Blocks DELTA SYNC",
},
],
},
Expand Down Expand Up @@ -985,91 +990,6 @@ Array [
],
"name": "WpBlock",
},
Object {
"fields": Array [
"author",
"authorDatabaseId",
"authorId",
"blocks",
"blocksJSON",
"content",
"contentType",
"databaseId",
"date",
"dateGmt",
"desiredSlug",
"enclosure",
"guid",
"id",
"lastEditedBy",
"lastUpdateTime",
"link",
"modified",
"modifiedGmt",
"previewedDatabaseId",
"previewedParentDatabaseId",
"seo",
"slug",
"status",
"template",
"title",
"uri",
"nodeType",
"parent",
"children",
"internal",
],
"name": "WpBlockEditorPreview",
},
Object {
"fields": Array [
"totalCount",
"edges",
"nodes",
"pageInfo",
"distinct",
"max",
"min",
"sum",
"group",
],
"name": "WpBlockEditorPreviewConnection",
},
Object {
"fields": Array [
"next",
"node",
"previous",
],
"name": "WpBlockEditorPreviewEdge",
},
Object {
"fields": null,
"name": "WpBlockEditorPreviewFieldsEnum",
},
Object {
"fields": null,
"name": "WpBlockEditorPreviewFilterInput",
},
Object {
"fields": null,
"name": "WpBlockEditorPreviewFilterListInput",
},
Object {
"fields": Array [
"totalCount",
"edges",
"nodes",
"pageInfo",
"field",
"fieldValue",
],
"name": "WpBlockEditorPreviewGroupConnection",
},
Object {
"fields": null,
"name": "WpBlockEditorPreviewSortInput",
},
Object {
"fields": null,
"name": "WpBlockFilterInput",
Expand Down Expand Up @@ -5990,7 +5910,6 @@ Array [
Object {
"fields": Array [
"avatar",
"blockEditorPreviews",
"capabilities",
"comments",
"databaseId",
Expand Down Expand Up @@ -6127,16 +6046,6 @@ Array [
"fields": null,
"name": "WpUserSortInput",
},
Object {
"fields": Array [
"nodes",
],
"name": "WpUserToBlockEditorPreviewConnection",
},
Object {
"fields": null,
"name": "WpUserToBlockEditorPreviewConnectionFilterInput",
},
Object {
"fields": Array [
"nodes",
Expand Down Expand Up @@ -6448,6 +6357,17 @@ Array [
"fields": null,
"name": "ActionMonitorActionToTermNodeConnectionWhereArgs",
},
Object {
"fields": null,
"name": "AttachFeaturedImageToNodeByIdInput",
},
Object {
"fields": Array [
"clientMutationId",
"success",
],
"name": "AttachFeaturedImageToNodeByIdPayload",
},
Object {
"fields": Array [
"default",
Expand Down Expand Up @@ -10568,6 +10488,17 @@ Array [
"fields": null,
"name": "RelationEnum",
},
Object {
"fields": null,
"name": "RemoveFeaturedImageFromNodeByIdInput",
},
Object {
"fields": Array [
"clientMutationId",
"success",
],
"name": "RemoveFeaturedImageFromNodeByIdPayload",
},
Object {
"fields": null,
"name": "ResetUserPasswordInput",
Expand Down Expand Up @@ -10641,6 +10572,7 @@ Array [
},
Object {
"fields": Array [
"attachFeaturedImageToNodeById",
"createActionMonitorAction",
"createCategory",
"createComment",
Expand Down Expand Up @@ -10669,6 +10601,7 @@ Array [
"deleteUser",
"increaseCount",
"registerUser",
"removeFeaturedImageFromNodeById",
"resetUserPassword",
"restoreComment",
"sendPasswordResetEmail",
Expand Down
22 changes: 14 additions & 8 deletions integration-tests/gatsby-source-wordpress/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const testOnColdCacheOnly = isWarmCache ? test.skip : test

describe(`[gatsby-source-wordpress] Build default options`, () => {
beforeAll(async done => {
await urling({ url: `http://localhost:8001/graphql`, retry: 15 })
await urling({ url: `http://localhost:8001/graphql`, retry: 100 })

if (isWarmCache) {
done()
Expand Down Expand Up @@ -74,17 +74,23 @@ describe(`[gatsby-source-wordpress] Run tests on develop build`, () => {
process.exit(1)
}

if (isWarmCache) {
const response = await mutateSchema()
console.log(response)
} else {
const response = await resetSchema()
console.log(response)
try {
if (isWarmCache) {
const response = await mutateSchema()
console.log(response)
} else {
const response = await resetSchema()
console.log(response)
}
} catch (e) {
console.info(`Threw errors while mutating or unmutating WordPress`)
await new Promise(resolve => setTimeout(resolve, 1000))
process.exit(1)
}

gatsbyDevelopProcess = spawnGatsbyProcess(`develop`)

await urling(`http://localhost:8000`)
await urling(`http://localhost:8000`, { retry: 100 })
})

require(`../test-fns/index`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ RUN chmod +x /usr/local/bin/install-plugin
COPY install-wp-graphql-plugins.sh /usr/local/bin/install-wp-graphql-plugins
RUN chmod +x /usr/local/bin/install-wp-graphql-plugins

COPY plugins/* ${PLUGIN_DIR}/

EXPOSE 8001

CMD ["wait-for-it", "-t", "40", "db:3306", "--", "/usr/local/bin/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
// Plugin Name: WPGatsby Test Plugin (for tests only)

add_action( 'graphql_register_types', 'add_test_mutations' );

function add_test_mutations() {
register_graphql_mutation( "attachFeaturedImageToNodeById", [
'description' => 'Attaches a MediaItem database ID to a post featured image by database ID.',
'inputFields' => [
'mediaItemId' => [
'type' => 'Int'
],
'postId' => [
'type' => 'Int'
]
],
'outputFields' => [
'success' => [
'type' => 'Boolean'
]
],
'mutateAndGetPayload' => function( $input ) {

if ( empty( $input['mediaItemId'] ) || empty( $input['postId'] ) ) {
return [
'success' => false
];
}

$selectedPost = get_post( $input['postId'] );
$selectedMediaItem = get_post( $input['mediaItemId'] );


if ( ! $selectedPost || ! $selectedMediaItem ) {
return [
'success' => false,
];
}

set_post_thumbnail( $selectedPost->ID, $selectedMediaItem->ID );

wp_update_post( [
'ID' => $selectedPost->ID,
] );

return [
'success' => true,
];
}
] );

register_graphql_mutation( "removeFeaturedImageFromNodeById", [
'description' => 'Removes a post featured image by post database ID.',
'inputFields' => [
'postId' => [
'type' => 'Int'
]
],
'outputFields' => [
'success' => [
'type' => 'Boolean'
]
],
'mutateAndGetPayload' => function( $input ) {

if ( empty( $input['postId'] ) ) {
return [
'success' => false
];
}

$selectedPost = get_post( $input['postId'] );


if ( ! $selectedPost ) {
return [
'success' => false,
];
}

delete_post_meta( $selectedPost->ID, '_thumbnail_id' );

wp_update_post( [
'ID' => $selectedPost->ID,
] );

return [
'success' => true,
];
}
] );

}

?>
6 changes: 5 additions & 1 deletion integration-tests/gatsby-source-wordpress/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const requestConcurrency = 1

const mediaItemTypeSettings = {
localFile: {
excludeByMimeTypes: ['video/mp4'],
excludeByMimeTypes: ["video/mp4"],
/**
* This is set to one byte smaller than the largest image in the Gatsby site so that we will have exactly one image that isn't fetched
* during the site build
Expand Down Expand Up @@ -44,6 +44,10 @@ const wpPluginOptions = !process.env.DEFAULT_PLUGIN_OPTIONS
DatabaseIdentifier: {
exclude: true,
},
BlockEditorPreview: {
// we need to exclude this type because nodes of this type (which are added by wp-graphql-gutenberg) seem to be somewhat unpredictably created in WP and mess up our tests that are counting total nodes of the WpContentNode type (which is an interface that includes all content nodes including WpBlockEditorPreview).
exclude: true,
},
User: {
excludeFieldNames: [
`extraCapabilities`,
Expand Down
Loading