I guess the number of people using GraphQL to display WordPress data via another framework in a headless setup may be few and far apart. Seems I just have to register the variables myself rather than putting that burden on you. Here’s a quick Claude code plugin.
<?php
/**
* Plugin Name: ISC + WPGraphQL Bridge
* Description: Exposes Image Source Control attachment meta in WPGraphQL.
* Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'graphql_register_types', function() {
register_graphql_field( 'MediaItem', 'imageSourceControl', [
'type' => 'ImageSourceControlMeta',
'description' => __( 'Image Source Control metadata for this media item.', 'your-textdomain' ),
'resolve' => function( $media_item ) {
$attachment_id = isset( $media_item->databaseId ) ? (int) $media_item->databaseId : 0;
if ( ! $attachment_id ) {
return null;
}
$license = get_post_meta( $attachment_id, 'isc_image_licence', true );
if ( empty( $license ) ) {
$license = get_post_meta( $attachment_id, 'isc_image_license', true );
}
return [
'source' => get_post_meta( $attachment_id, 'isc_image_source', true ),
'sourceUrl' => get_post_meta( $attachment_id, 'isc_image_source_url', true ),
'license' => $license,
'isOwnSource' => (bool) get_post_meta( $attachment_id, 'isc_image_source_own', true ),
];
},
] );
register_graphql_object_type( 'ImageSourceControlMeta', [
'description' => __( 'Metadata from the Image Source Control plugin.', 'your-textdomain' ),
'fields' => [
'source' => [
'type' => 'String',
'description' => __( 'Image source name.', 'your-textdomain' ),
],
'sourceUrl' => [
'type' => 'String',
'description' => __( 'Image source URL.', 'your-textdomain' ),
],
'license' => [
'type' => 'String',
'description' => __( 'Image license.', 'your-textdomain' ),
],
'isOwnSource' => [
'type' => 'Boolean',
'description' => __( 'Whether the image is marked as in-house / own source.', 'your-textdomain' ),
],
],
] );
} );