• Resolved christiankozalla

    (@christiankozalla)


    Hi everyone!

    I’m developing a custom frontend with Next.js from a deployed WordPress site, that is currently using a theme (Cornerstone, I think). The site is currently online via the theme and should stay online until I’ve finished developing the custom frontend.

    My question is: Can I install the WPGraphQL plugin without breaking the active theme? Will the whole WordPress setup continue working, just adding the graphql endpoint?

    Additional question: Since I’ve already played around with the WordPress REST API, which only return “rendered” content as HTML strings for unauthenticated requests, I would like to get “raw” content from the API. Does WPGraphQL provide raw content (without HTML) of pages and posts?

    Thank you very much. I appreciate your help!

Viewing 1 replies (of 1 total)
  • Plugin Author Jason Bahl

    (@jasonbahl)

    You should be able to activate WPGraphQL without having any issues.

    WPGraphQL follows the Access Control privileges of WordPress, as does the WP REST API, so both APIs return the “rendered” content of posts to public users.

    You can filter WPGraphQL to return RAW content to non-authenticated users if you chose to allow it.

    One way:

    Register a new field.

    php
    <?php
    add_action( 'graphql_register_types', function() {
    
      register_graphql_field( 'Post', 'rawContent', [
        'type' => 'String',
        'resolve' => function( $post, $args, $context, $info ) {
           $raw_post = get_post( $post->databaseId );
           return $raw_post->post_content;
        }
      ]);
    
    } );
    
Viewing 1 replies (of 1 total)

The topic ‘Will WPGraphQL be compatible with an active theme alongside?’ is closed to new replies.