• Resolved bcw00

    (@bcwint00)


    Hi there. Been using your plugin a while and like it. Does it have any sort of integration for WPGraphQL outputs? I’m working on a headless theme and I’m trying to pull as many variables as possible together for my theme in Astro. If not, can you point me the basic outputs so maybe I can write up a custom function to create additional variables in GraphQL?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Thomas Maier

    (@webzunft)

    Hi bcw00,

    thanks for reaching out.

    I have no experience with WPGraphQL and appreciate any input, if it makes a good addition for the plugin.

    I am not sure which kind of variables you are looking for, but if you need to know where which information is stored in the database, you can look into the uninstall.php file in the plugin’s root directory. It removes any data stored by the plugin (Lite and Pro).

    Please let me know if you need anything else.

    Thomas

    Thread Starter bcw00

    (@bcwint00)

    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' ),
    ],
    ],
    ] );

    } );
    Plugin Author Thomas Maier

    (@webzunft)

    Thanks for sharing the code!

    I know too little about GraphQL to test it properly and include it into the plugin, but if another user asks, I will direct them to your post.

    Thanks,
    Thomas

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.